add route for site
This commit is contained in:
parent
78da18a80b
commit
b8880d0a94
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,5 +1,3 @@
|
||||
uploads/*
|
||||
tmp/*
|
||||
.env
|
||||
site
|
||||
site/*
|
||||
.env
|
@ -10,6 +10,12 @@ const imageCollection = db.collection('images');
|
||||
const userTable = db.collection('users');
|
||||
|
||||
|
||||
export const site = async (ctx: RouterContext) => {
|
||||
if(ctx.params.filename == "sw.js" || ctx.params.filename == "script.js"){
|
||||
ctx.response.type = "text/javascript"
|
||||
}
|
||||
ctx.response.body = await renderFileToString(`${Deno.cwd()}/site/${ctx.params.filename}`, {})
|
||||
}
|
||||
|
||||
export const icons = async (ctx: RouterContext, next: any) => {
|
||||
const identifier = ctx.params.filename
|
||||
@ -124,7 +130,6 @@ export const getImage = async (ctx: RouterContext) => {
|
||||
ctx.response.type = info.mime;
|
||||
ctx.response.body = img;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const deleteImage = async (ctx: RouterContext) => {
|
||||
@ -151,7 +156,6 @@ export const deleteImage = async (ctx: RouterContext) => {
|
||||
}else{
|
||||
ctx.response.body = {message: 'Unauthorized'};
|
||||
ctx.response.status = 401
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Application, Router } from "https://deno.land/x/oak/mod.ts";
|
||||
import { getImage, uploadImage, deleteImage, chunks, mergeChunks, announce, icons} from './routes.ts';
|
||||
import { getImage, uploadImage, deleteImage, chunks, mergeChunks, announce, site, icons} from './routes.ts';
|
||||
import "https://deno.land/std@0.178.0/dotenv/load.ts";
|
||||
|
||||
|
||||
@ -16,6 +16,7 @@ router.get('/', async(ctx: RouterContext, next: any) => {
|
||||
}
|
||||
|
||||
})
|
||||
.get('/:filename', site)
|
||||
.get('/i/:filename', icons)
|
||||
.post('/upload', uploadImage)
|
||||
.post('/announce', announce)
|
||||
@ -24,7 +25,6 @@ router.get('/', async(ctx: RouterContext, next: any) => {
|
||||
.delete('/image/:filename', deleteImage)
|
||||
.get('/image/:filename', getImage)
|
||||
|
||||
|
||||
const app = new Application();
|
||||
|
||||
app.use(router.routes())
|
||||
|
Loading…
Reference in New Issue
Block a user