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