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 { checkFileType, getFileName, parseRange } from '../utils'
|
||||||
import { R2ListOptions } from "@cloudflare/workers-types";
|
import { R2ListOptions } from "@cloudflare/workers-types";
|
||||||
|
|
||||||
const auth = async (request : Request, env : Env) => {
|
const auth = async (request: Request, env: Env) => {
|
||||||
const method = request.method;
|
const method = request.method;
|
||||||
// console.log(method)
|
// console.log(method)
|
||||||
if (method == "GET" || method == "OPTIONS") {
|
if (method == "GET" || method == "OPTIONS") {
|
||||||
|
@ -28,7 +28,7 @@ const auth = async (request : Request, env : Env) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检测token是否有效
|
// 检测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 data = await req.json() as AuthToken
|
||||||
const token = data.token
|
const token = data.token
|
||||||
if (!token) {
|
if (!token) {
|
||||||
|
@ -45,8 +45,9 @@ 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 BASE_URL = await env.XK.get('BASE_URL')
|
||||||
|
console.log("BASE_URL=" + 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,8 +75,8 @@ router.post('/list', auth, async (req : Request, env : Env) => {
|
||||||
const cursor = list.cursor
|
const cursor = list.cursor
|
||||||
const objs = list.objects
|
const objs = list.objects
|
||||||
const urls = objs.map(it => {
|
const urls = objs.map(it => {
|
||||||
return <ImgItem> {
|
return <ImgItem>{
|
||||||
url: BASE_URL+`${include}/${it.key}`,
|
url: BASE_URL + `${include}/${it.key}`,
|
||||||
key: it.key,
|
key: it.key,
|
||||||
size: it.size
|
size: it.size
|
||||||
}
|
}
|
||||||
|
@ -89,7 +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 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")
|
||||||
|
@ -113,7 +114,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: BASE_URL+`/${object.key}`,
|
url: BASE_URL + `/${object.key}`,
|
||||||
filename: item.name
|
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 {
|
try {
|
||||||
const data = await req.json() as Folder
|
const data = await req.json() as Folder
|
||||||
const regx = /^[A-Za-z_]+$/
|
const regx = /^[A-Za-z_]+$/
|
||||||
|
@ -137,7 +138,7 @@ router.post("/folder", auth, async (req: Request, env: Env) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
// 删除key
|
// 删除key
|
||||||
router.get('/del/:id+', async (req : Request, env: Env) => {
|
router.get('/del/:id+', async (req: Request, env: Env) => {
|
||||||
const key = req.params.id
|
const key = req.params.id
|
||||||
if (!key) {
|
if (!key) {
|
||||||
return json(Fail("not delete key"))
|
return json(Fail("not delete key"))
|
||||||
|
@ -151,7 +152,7 @@ router.get('/del/:id+', async (req : Request, env: Env) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
// delete image
|
// delete image
|
||||||
router.delete("/", auth, async (req : Request, env: Env) => {
|
router.delete("/", auth, async (req: Request, env: Env) => {
|
||||||
const params = await req.json()
|
const params = await req.json()
|
||||||
// console.log(params)
|
// console.log(params)
|
||||||
const keys = params.keys;
|
const keys = params.keys;
|
||||||
|
@ -161,7 +162,7 @@ router.delete("/", auth, async (req : Request, env: Env) => {
|
||||||
const arr = keys.split(',')
|
const arr = keys.split(',')
|
||||||
try {
|
try {
|
||||||
for (let it of arr) {
|
for (let it of arr) {
|
||||||
if(it && it.length) {
|
if (it && it.length) {
|
||||||
await env.PICX.delete(it)
|
await env.PICX.delete(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,7 +173,7 @@ router.delete("/", auth, async (req : Request, env: Env) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
// image detail
|
// image detail
|
||||||
router.get("/:id+", async (req : Request, env : Env) => {
|
router.get("/:id+", async (req: Request, env: Env) => {
|
||||||
let id = req.params.id
|
let id = req.params.id
|
||||||
const range = parseRange(req.headers.get('range'))
|
const range = parseRange(req.headers.get('range'))
|
||||||
const object = await env.PICX.get(id, {
|
const object = await env.PICX.get(id, {
|
||||||
|
|
Loading…
Reference in New Issue