fix:basic_url处理
This commit is contained in:
parent
d515b07e2f
commit
5afed2da14
functions/rest
|
@ -1,7 +1,6 @@
|
||||||
import { error } from 'itty-router-extras';
|
import { error } from 'itty-router-extras';
|
||||||
|
|
||||||
export interface Env {
|
export interface Env {
|
||||||
BASE_URL: string
|
|
||||||
XK: KVNamespace
|
XK: KVNamespace
|
||||||
PICX: R2Bucket
|
PICX: R2Bucket
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@ router.post('/checkToken', async (req : Request, env : Env) => {
|
||||||
|
|
||||||
// list image
|
// 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')
|
||||||
const data = await req.json() as ImgReq
|
const data = await req.json() as ImgReq
|
||||||
if (!data.limit) {
|
if (!data.limit) {
|
||||||
data.limit = 10
|
data.limit = 10
|
||||||
|
@ -74,7 +75,7 @@ router.post('/list', auth, async (req : Request, env : Env) => {
|
||||||
const objs = list.objects
|
const objs = list.objects
|
||||||
const urls = objs.map(it => {
|
const urls = objs.map(it => {
|
||||||
return <ImgItem> {
|
return <ImgItem> {
|
||||||
url: `${env.BASE_URL}/rest/${it.key}`,
|
url: `${BASE_URL}${include}/${it.key}`,
|
||||||
key: it.key,
|
key: it.key,
|
||||||
size: it.size
|
size: it.size
|
||||||
}
|
}
|
||||||
|
@ -89,6 +90,7 @@ router.post('/list', auth, async (req : Request, env : Env) => {
|
||||||
|
|
||||||
// batch upload file
|
// 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 files = await req.formData()
|
||||||
const images = files.getAll("files")
|
const images = files.getAll("files")
|
||||||
const errs = []
|
const errs = []
|
||||||
|
@ -111,7 +113,7 @@ router.post('/upload', auth, async (req: Request, env : Env) => {
|
||||||
urls.push({
|
urls.push({
|
||||||
key: object.key,
|
key: object.key,
|
||||||
size: object.size,
|
size: object.size,
|
||||||
url: `${env.BASE_URL}/rest/${object.key}`,
|
url: `${BASE_URL}/${object.key}`,
|
||||||
filename: item.name
|
filename: item.name
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue