Skip to content

Commit

Permalink
Update index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
iiop123 committed Nov 12, 2022
1 parent 3a0ebbc commit f71829d
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,30 @@ router.post(
let form=req.body.formData()
let out=[]
let img=(await form).getAll('img')
const img_check=/^[\s\S]*\.(pdf|sh|zip|txt|docx|xlsx|exe|apk)$/
for (let i = 0; i < img.length; i++) {
if (img_check.test(img[i].name)) {
res.status=400
res.body={name:img[i].name,err:'非图片文件'}
}else{
let url=await randomString()
let check=await LINK.get(url)
if (check!==null) {
url=await randomString()
}
let stream=img[i].stream()
await LINK.put(url,stream)
await LINK.put(url,stream,{
metadata:{
size:img[i].size,
name:url,
date:new Date().getTime()
}
})
out.push(req.url+'/img/'+url)
}
res.body = {src:out}
}
}
}}
);
router.get('/api/img/:p', async ({req,res})=>{
let body=await LINK.get(req.params.p,{cacheTtl:864000,type:"stream"})
res.body=body

})

// Favicon route for fun :)
router.get('/favicon.ico', ({ res }) => {
Expand All @@ -75,4 +81,4 @@ router.post(
new Application()
.use(normalizePathnameMiddleware)
.use(router.middleware)
.listen();
.listen();

0 comments on commit f71829d

Please sign in to comment.