cdn_cache.js 929 Bytes
/**
 *
 * @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',
            }]
        }
        await ctx.render('action/cdn_cache', date);
    },
    async clear(ctx) {
        let queryUris = ctx.request.body.query_uri;
        let objectType = ctx.request.body.object_type;
        if (queryUris.trim() && objectType) {
            CdnCache.removeCache(queryUris, objectType);    
        }
        return ctx.body = {
            code: 200
        };
    }
}
r.get('/query', cdnCache.query);
r.post('/clear', cdnCache.clear);

module.exports = r;