forked from labring/laf
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(file): 重构LSF 文件管理方式;新增文件访问令牌云函数;修复文件API安全漏洞;
- Loading branch information
Showing
7 changed files
with
139 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
/** | ||
* 本函数可发放文件访问令牌,用于下载或上传文件 | ||
* @TODO 你可以修改本函数,以实现符合业务的文件访问授权逻辑 | ||
* | ||
* @body {string} namespace 文件存储的名字空间 | ||
* @body {string} filename 文件名 | ||
* @body {string} type 授权的操作,取值为: "read" | "create" | "all" | ||
* @body {number} expire 令牌有效期,单位为秒,默认为一小时,即 3600 | ||
*/ | ||
|
||
exports.main = async function (ctx) { | ||
const uid = ctx.auth?.uid | ||
if (!uid) return 'error: unauthorized' | ||
|
||
const ns = ctx.body?.namespace ?? undefined | ||
const fn = ctx.body?.filename ?? undefined | ||
const op = ctx.body?.type ?? 'read' | ||
const expire = ctx.body?.expire ?? 3600 | ||
|
||
if (!ns) { | ||
return 'error: invalid namespace' | ||
} | ||
|
||
const exp = Math.floor(Date.now()/1000) + expire | ||
const payload = { ns, op, exp, fn } | ||
|
||
return less.getToken(payload) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"label": "文件访问令牌", | ||
"name": "file-token", | ||
"description": "文件访问令牌", | ||
"enableHTTP": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters