chore:打印baseUrl

This commit is contained in:
李亮亮 2024-01-15 16:08:47 +08:00
parent 07db42a346
commit 92d0c302a5
1 changed files with 13 additions and 12 deletions

View File

@ -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 <ImgItem> {
url: BASE_URL+`${include}/${it.key}`,
return <ImgItem>{
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
})
}
@ -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, {