添加前端页面以及相关打包脚本和内置 web 的逻辑

This commit is contained in:
2026-01-14 23:09:16 +08:00
parent e456d3a823
commit 9b646321e1
45 changed files with 583 additions and 10 deletions

View File

@@ -115,6 +115,20 @@ func (h *PickupHandler) Pickup(c *gin.Context) {
}
}
// 生成文件下载绝对路径直链
scheme := "http"
if c.Request.TLS != nil || c.GetHeader("X-Forwarded-Proto") == "https" {
scheme = "https"
}
host := c.Request.Host
if forwardedHost := c.GetHeader("X-Forwarded-Host"); forwardedHost != "" {
host = forwardedHost
}
for i := range batch.FileItems {
batch.FileItems[i].DownloadURL = fmt.Sprintf("%s://%s/api/files/%s/%s", scheme, host, batch.FileItems[i].ID, batch.FileItems[i].OriginalName)
}
c.JSON(http.StatusOK, model.SuccessResponse(PickupResponse{
Remark: batch.Remark,
ExpireAt: batch.ExpireAt,
@@ -129,14 +143,16 @@ func (h *PickupHandler) Pickup(c *gin.Context) {
// DownloadFile 下载单个文件
// @Summary 下载单个文件
// @Description 根据文件 ID 下载单个文件。可选提供带 pickup scope 的 API Token。
// @Description 根据文件 ID 下载单个文件。支持直观的文件名结尾以方便下载工具识别。可选提供带 pickup scope 的 API Token。
// @Tags Public
// @Security APITokenAuth
// @Param file_id path string true "文件 ID (UUID)"
// @Param file_id path string true "文件 ID (UUID)"
// @Param filename path string false "文件名"
// @Produce application/octet-stream
// @Success 200 {file} file
// @Failure 404 {object} model.Response
// @Failure 410 {object} model.Response
// @Router /api/files/{file_id}/{filename} [get]
// @Router /api/files/{file_id}/download [get]
func (h *PickupHandler) DownloadFile(c *gin.Context) {
fileID := c.Param("file_id")
@@ -155,7 +171,12 @@ func (h *PickupHandler) DownloadFile(c *gin.Context) {
if h.batchService.IsExpired(&batch) {
h.batchService.MarkAsExpired(&batch)
c.JSON(http.StatusGone, model.ErrorResponse(model.CodeGone, "batch expired"))
// 按照需求,如果不存在(已在上面处理)或达到上限,返回 404
if batch.ExpireType == "download" && batch.DownloadCount >= batch.MaxDownloads {
c.JSON(http.StatusNotFound, model.ErrorResponse(model.CodeNotFound, "file not found or download limit reached"))
} else {
c.JSON(http.StatusGone, model.ErrorResponse(model.CodeGone, "batch expired"))
}
return
}