cdn_cache.js 1.27 KB
/**
 *
 * @author: chenfeng<feng.chen@yoho.cn>
 * @date: 16/10/19
 */

'use strict';

const Router = require('koa-router');
const {
    CdnCache
} = require('../../models');

const r = new Router();

const cdnCache = {
    async query(ctx) {
        let date = {
            typeList: [{
                name: '文件',
                typeName: 'File',
            }, {
                name: '目录',
                typeName: 'Directory',
            }],
            cloudList: [{
                name: '腾讯云',
                cloudName: 'qcloud',
            }, {
                name: '阿里云',
                cloudName: 'aliyun',
            }, {
                name: '七牛云',
                cloudName: 'qiniu'
            }]
        }
        await ctx.render('action/cdn_cache', date);
    },
    async clear(ctx) {
        let queryUris = ctx.request.body.query_uri;
        let objectType = ctx.request.body.object_type;
        let cloud = ctx.request.body.cloud || 'aliyun'; // aliyun or qcloud
        if (queryUris.trim() && objectType) {
            CdnCache.removeCache(queryUris, objectType, cloud);    
        }
        return ctx.body = {
            code: 200
        };
    }
}
r.get('/query', cdnCache.query);
r.post('/clear', cdnCache.clear);

module.exports = r;