Skip to content

Commit

Permalink
style: fix eslint error
Browse files Browse the repository at this point in the history
  • Loading branch information
bangbang93 committed Mar 26, 2024
1 parent 4e2b7bd commit 2899f27
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/storage/alist-webdav.storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@ import Keyv from 'keyv'
import {KeyvFile} from 'keyv-file'
import ms from 'ms'
import {join} from 'path'
import {cwd} from 'process'
import {WebdavStorage} from './webdav.storage.js'

export class AlistWebdavStorage extends WebdavStorage {
protected readonly redirectUrlCache = new Keyv<string>({
namespace: 'redirectUrl',
ttl: ms('1h'),
store: new KeyvFile({
filename: join(cwd(), 'cache', 'redirectUrl.json'),
filename: join(process.cwd(), 'cache', 'redirectUrl.json'),
writeDelay: ms('1m'),
}),
})

public async express(hashPath: string, req: Request, res: Response): Promise<{ bytes: number; hits: number }> {
public async express(hashPath: string, req: Request, res: Response): Promise<{bytes: number; hits: number}> {
const cachedUrl = await this.redirectUrlCache.get(hashPath)
const size = this.getSize(this.files.get(req.params.hash)?.size ?? 0, req.headers.range)
if (cachedUrl) {
Expand All @@ -26,14 +25,16 @@ export class AlistWebdavStorage extends WebdavStorage {
}
const path = join(this.basePath, hashPath)
const url = this.client.getFileDownloadLink(path)
const resp = await got.get(url, {followRedirect: false,
const resp = await got.get(url, {
followRedirect: false,
responseType: 'buffer',
headers: {
range: req.headers.range,
},
https: {
rejectUnauthorized: false,
}})
},
})
if (resp.statusCode >= 200 && resp.statusCode < 300) {
res.status(resp.statusCode).send(resp.body)
return {bytes: resp.body.length, hits: 1}
Expand Down

0 comments on commit 2899f27

Please sign in to comment.