From 92d0c302a506a387dd62d7c9e41904fc7694079d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=BA=AE=E4=BA=AE?= Date: Mon, 15 Jan 2024 16:08:47 +0800 Subject: [PATCH] =?UTF-8?q?chore:=E6=89=93=E5=8D=B0baseUrl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions/rest/routes/index.ts | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/functions/rest/routes/index.ts b/functions/rest/routes/index.ts index 8295817..d7a40b8 100644 --- a/functions/rest/routes/index.ts +++ b/functions/rest/routes/index.ts @@ -5,7 +5,7 @@ import StatusCode, { Ok, Fail, Build, ImgItem, ImgList, ImgReq, Folder, AuthToke import { checkFileType, getFileName, parseRange } from '../utils' import { R2ListOptions } from "@cloudflare/workers-types"; -const auth = async (request : Request, env : Env) => { +const auth = async (request: Request, env: Env) => { const method = request.method; // console.log(method) if (method == "GET" || method == "OPTIONS") { @@ -28,7 +28,7 @@ const auth = async (request : Request, env : Env) => { } // 检测token是否有效 -router.post('/checkToken', async (req : Request, env : Env) => { +router.post('/checkToken', async (req: Request, env: Env) => { const data = await req.json() as AuthToken const token = data.token if (!token) { @@ -45,8 +45,9 @@ router.post('/checkToken', async (req : Request, env : Env) => { }) // list image -router.post('/list', auth, async (req : Request, env : Env) => { +router.post('/list', auth, async (req: Request, env: Env) => { const BASE_URL = await env.XK.get('BASE_URL') + console.log("BASE_URL=" + BASE_URL) const data = await req.json() as ImgReq if (!data.limit) { data.limit = 10 @@ -74,8 +75,8 @@ router.post('/list', auth, async (req : Request, env : Env) => { const cursor = list.cursor const objs = list.objects const urls = objs.map(it => { - return { - url: BASE_URL+`${include}/${it.key}`, + return { + url: BASE_URL + `${include}/${it.key}`, key: it.key, size: it.size } @@ -89,7 +90,7 @@ router.post('/list', auth, async (req : Request, env : Env) => { }) // batch upload file -router.post('/upload', auth, async (req: Request, env : Env) => { +router.post('/upload', auth, async (req: Request, env: Env) => { const BASE_URL = await env.XK.get('BASE_URL') const files = await req.formData() const images = files.getAll("files") @@ -113,7 +114,7 @@ router.post('/upload', auth, async (req: Request, env : Env) => { urls.push({ key: object.key, size: object.size, - url: BASE_URL+`/${object.key}`, + url: BASE_URL + `/${object.key}`, filename: item.name }) } @@ -122,7 +123,7 @@ router.post('/upload', auth, async (req: Request, env : Env) => { }) // 创建目录 -router.post("/folder", auth, async (req: Request, env: Env) => { +router.post("/folder", auth, async (req: Request, env: Env) => { try { const data = await req.json() as Folder const regx = /^[A-Za-z_]+$/ @@ -137,7 +138,7 @@ router.post("/folder", auth, async (req: Request, env: Env) => { }) // 删除key -router.get('/del/:id+', async (req : Request, env: Env) => { +router.get('/del/:id+', async (req: Request, env: Env) => { const key = req.params.id if (!key) { return json(Fail("not delete key")) @@ -151,7 +152,7 @@ router.get('/del/:id+', async (req : Request, env: Env) => { }) // delete image -router.delete("/", auth, async (req : Request, env: Env) => { +router.delete("/", auth, async (req: Request, env: Env) => { const params = await req.json() // console.log(params) const keys = params.keys; @@ -161,7 +162,7 @@ router.delete("/", auth, async (req : Request, env: Env) => { const arr = keys.split(',') try { for (let it of arr) { - if(it && it.length) { + if (it && it.length) { await env.PICX.delete(it) } } @@ -172,7 +173,7 @@ router.delete("/", auth, async (req : Request, env: Env) => { }) // image detail -router.get("/:id+", async (req : Request, env : Env) => { +router.get("/:id+", async (req: Request, env: Env) => { let id = req.params.id const range = parseRange(req.headers.get('range')) const object = await env.PICX.get(id, {