From 5afed2da14e67ad9d0cf9d8ff8baf1c4b3b701a5 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 15:55:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:basic=5Furl=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions/rest/[[path]].ts | 1 - functions/rest/routes/index.ts | 6 ++++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/functions/rest/[[path]].ts b/functions/rest/[[path]].ts index 557e39a..cf4bf49 100644 --- a/functions/rest/[[path]].ts +++ b/functions/rest/[[path]].ts @@ -1,7 +1,6 @@ import { error } from 'itty-router-extras'; export interface Env { - BASE_URL: string XK: KVNamespace PICX: R2Bucket } diff --git a/functions/rest/routes/index.ts b/functions/rest/routes/index.ts index 9cec42f..a68ae4b 100644 --- a/functions/rest/routes/index.ts +++ b/functions/rest/routes/index.ts @@ -46,6 +46,7 @@ router.post('/checkToken', async (req : Request, env : Env) => { // list image router.post('/list', auth, async (req : Request, env : Env) => { + const BASE_URL = await env.XK.get('BASE_URL') const data = await req.json() as ImgReq if (!data.limit) { data.limit = 10 @@ -74,7 +75,7 @@ router.post('/list', auth, async (req : Request, env : Env) => { const objs = list.objects const urls = objs.map(it => { return { - url: `${env.BASE_URL}/rest/${it.key}`, + url: `${BASE_URL}${include}/${it.key}`, key: it.key, size: it.size } @@ -89,6 +90,7 @@ router.post('/list', auth, async (req : Request, env : Env) => { // batch upload file 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") const errs = [] @@ -111,7 +113,7 @@ router.post('/upload', auth, async (req: Request, env : Env) => { urls.push({ key: object.key, size: object.size, - url: `${env.BASE_URL}/rest/${object.key}`, + url: `${BASE_URL}/${object.key}`, filename: item.name }) }