chore:打印baseUrl
This commit is contained in:
parent
07db42a346
commit
92d0c302a5
|
@ -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
|
||||
})
|
||||
}
|
||||
|
@ -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, {
|
||||
|
|
Loading…
Reference in New Issue