ext/web W5: multipart upload receive and download
Add app.upload/download routes over # storage, offline media validate/save helpers, form type=file + enctype, and curl live gold coverage. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
034f52b7e7
commit
a900fd550f
18 files changed
+1214
-15
No files matched your search
+53
-1
@@ -417,7 +417,7 @@ Tables stay as data; `configure` assembles them. 配置即数据、装配即函
|
||||
|
||||
## listen
|
||||
|
||||
Serve `/`, routed pages, `/_part/{id}` (home) and `{path}/_part/{id}` (routes), `/_form/{id}` (from mounts + page embeds), optional `/static` (or custom mount), and optional `/admin`.
|
||||
Serve `/`, routed pages, `/_part/{id}` (home) and `{path}/_part/{id}` (routes), `/_form/{id}` (from mounts + page embeds), optional `/static` (or custom mount), optional `/admin`, and any `upload` / `download` routes.
|
||||
|
||||
**> web_listen app=`self`**
|
||||
|
||||
@@ -450,6 +450,27 @@ Register an RSS 2.0 feed at `path` (e.g. `/feed.xml`) backed by a DB table.
|
||||
|
||||
**> web_app_route_rss app=`self` path=`path` table=`table` limit=`limit` order=`order` title=`title` link=`link` description=`description`**
|
||||
|
||||
## upload
|
||||
+ `path`=/_upload
|
||||
+ `field`=file
|
||||
+ `storage`
|
||||
+ `prefix`=uploads/
|
||||
+ `max_bytes`=5242880
|
||||
+ `types`=None
|
||||
|
||||
Mount `POST path` for multipart file upload. `storage` is a `# storage` handle or `file:…` / `s3://…` URL. Optional `types` is a `|type|ext|` / `|类型|扩展名|` allowlist (or a MIME CSV string). Success returns JSON `{ok,key,size,content_type}`.
|
||||
|
||||
**> web_app_upload app=`self` path=`path` field=`field` storage=`storage` prefix=`prefix` max_bytes=`max_bytes` types=`types`**
|
||||
|
||||
## download
|
||||
+ `path`=/_media/{*key}
|
||||
+ `storage`
|
||||
+ `disposition`=attachment
|
||||
|
||||
Mount `GET path` to stream an object. Path must capture `key` (use `{*key}` for nested keys). `disposition` is `attachment` or `inline`.
|
||||
|
||||
**> web_app_download app=`self` path=`path` storage=`storage` disposition=`disposition`**
|
||||
|
||||
# auth
|
||||
+ `users`
|
||||
+ `session_ttl`=3600
|
||||
@@ -569,6 +590,37 @@ Provide either `body` (text) or `path` (local file to upload).
|
||||
*url = self[^url]*
|
||||
**> web_storage_list url=`url` prefix=`prefix`**
|
||||
|
||||
# media
|
||||
+ `storage`=None
|
||||
|
||||
Offline helpers for upload validation and saving into `# storage` (also used by HTTP `app.upload`).
|
||||
|
||||
> ensure_plugin
|
||||
**> web_media_new storage=`storage`**
|
||||
|
||||
## validate
|
||||
+ `filename`
|
||||
+ `content_type`="application/octet-stream"
|
||||
+ `size`
|
||||
+ `max_bytes`=5242880
|
||||
+ `types`=None
|
||||
|
||||
**> web_upload_validate filename=`filename` content_type=`content_type` size=`size` max_bytes=`max_bytes` types=`types`**
|
||||
|
||||
## save
|
||||
+ `path`
|
||||
+ `key`=None
|
||||
+ `content_type`="application/octet-stream"
|
||||
+ `prefix`=uploads/
|
||||
+ `storage`=None
|
||||
|
||||
*st = storage*
|
||||
1. `st` == None
|
||||
*st = self[^storage]*
|
||||
2. *
|
||||
|
||||
**> web_upload_save storage=`st` path=`path` key=`key` content_type=`content_type` prefix=`prefix`**
|
||||
|
||||
# ws
|
||||
+ `timeout_sec`=30
|
||||
|
||||
|
||||
+53
-1
@@ -399,7 +399,7 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
|
||||
|
||||
## 监听
|
||||
|
||||
提供 `/`、路由页、首页 `/_part/{id}`、路由 `{路径}/_part/{id}`、`/_form/{id}`、可选静态目录,以及可选 `/admin`。
|
||||
提供 `/`、路由页、首页 `/_part/{id}`、路由 `{路径}/_part/{id}`、`/_form/{id}`、可选静态目录、可选 `/admin`,以及已挂载的 `上传` / `下载` 路由。
|
||||
|
||||
**> web_listen app=`self`**
|
||||
|
||||
@@ -432,6 +432,27 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
|
||||
|
||||
**> web_app_route_rss app=`self` path=`路径` table=`表` limit=`上限` order=`排序` title=`标题` link=`链接` description=`描述`**
|
||||
|
||||
## 上传
|
||||
+ `路径`=/_upload
|
||||
+ `字段`=file
|
||||
+ `存储`
|
||||
+ `前缀`=uploads/
|
||||
+ `最大字节`=5242880
|
||||
+ `类型`=None
|
||||
|
||||
挂载 `POST 路径` 接收 multipart 文件。`存储` 为 `# 存储` 句柄或 `file:…` / `s3://…` URL。可选 `类型` 为 `|类型|扩展名|` 允许表(或 MIME CSV)。成功返回 JSON `{ok,key,size,content_type}`。
|
||||
|
||||
**> web_app_upload app=`self` path=`路径` field=`字段` storage=`存储` prefix=`前缀` max_bytes=`最大字节` types=`类型`**
|
||||
|
||||
## 下载
|
||||
+ `路径`=/_media/{*key}
|
||||
+ `存储`
|
||||
+ `处置`=attachment
|
||||
|
||||
挂载 `GET 路径` 流式返回对象。路径须捕获 `key`(嵌套键用 `{*key}`)。`处置` 为 `attachment` 或 `inline`。
|
||||
|
||||
**> web_app_download app=`self` path=`路径` storage=`存储` disposition=`处置`**
|
||||
|
||||
# 鉴权
|
||||
+ `用户表`
|
||||
+ `会话时长`=3600
|
||||
@@ -551,6 +572,37 @@ SEO / OpenGraph 元数据表(`|键|值|`)。如 `title`、`description`、`c
|
||||
*url = self[^url]*
|
||||
**> web_storage_list url=`url` prefix=`前缀`**
|
||||
|
||||
# 媒体
|
||||
+ `存储`=None
|
||||
|
||||
上传校验与落盘辅助(HTTP `应用.上传` 亦用同一套规则)。
|
||||
|
||||
> 确保插件
|
||||
**> web_media_new storage=`存储`**
|
||||
|
||||
## 校验
|
||||
+ `文件名`
|
||||
+ `类型`="application/octet-stream"
|
||||
+ `大小`
|
||||
+ `最大字节`=5242880
|
||||
+ `允许`=None
|
||||
|
||||
**> web_upload_validate filename=`文件名` content_type=`类型` size=`大小` max_bytes=`最大字节` types=`允许`**
|
||||
|
||||
## 保存
|
||||
+ `路径`
|
||||
+ `键`=None
|
||||
+ `类型`="application/octet-stream"
|
||||
+ `前缀`=uploads/
|
||||
+ `存储`=None
|
||||
|
||||
*st = 存储*
|
||||
1. `st` == None
|
||||
*st = self[^storage]*
|
||||
2. *
|
||||
|
||||
**> web_upload_save storage=`st` path=`路径` key=`键` content_type=`类型` prefix=`前缀`**
|
||||
|
||||
# 实时
|
||||
+ `超时秒`=30
|
||||
|
||||
|
||||
Reference in new issue
Block a user