23 Commits

Author SHA1 Message Date
keven1024
7a3d03c41f feat: update primary color in CSS and enhance about page with relative time display and progress component 2025-06-22 01:07:09 +08:00
keven1024
0bdea93726 chore: add js-md5 dependency to pnpm-lock.yaml for file hashing 2025-06-22 00:49:14 +08:00
keven1024
f4740f4373 fix: improve max storage size handling in CreateUploadTask by using GetFileSize for better error management 2025-06-22 00:48:53 +08:00
keven1024
1ac21b3dd0 docs: update README to include new features and todos for file upload service 2025-06-22 00:47:32 +08:00
keven1024
76457a6e88 feat: replace SparkMD5 with js-md5 for file hash calculation and clean up unused code 2025-06-22 00:41:18 +08:00
keven1024
41e9df5ee8 feat: implement async file hash calculation using web workers for improved performance 2025-06-21 22:41:19 +08:00
keven1024
7f5149566c feat: enhance file upload progress view with error handling and user notifications 2025-06-21 16:45:30 +08:00
keven1024
24b4b2dc93 Merge branch 'main' of https://gitea.fudaoyuan.icu/keven/015 2025-06-21 15:51:24 +08:00
keven1024
9b1b89056d chore(backend): update version and build_time in GetStat function to use environment variables for better tracking 2025-06-21 15:51:01 +08:00
keven1024
46e3cf529c chore: update Dockerfile and Drone configuration to use VERSION and BUILD_TIME arguments for better build tracking 2025-06-21 15:47:11 +08:00
keven
3c18fcf8ff 更新 Dockerfile 2025-06-20 17:09:10 +08:00
keven
58403a291a chore: 添加 Prettier 配置文件以统一代码格式 2025-06-14 21:02:26 +08:00
keven
28154d09ad feat: 在文件上传进度视图中添加错误处理和用户提示,优化用户体验 2025-06-14 21:02:05 +08:00
keven
d77fc85fd3 feat: 在文件上传任务中添加存储空间检查,确保不超过最大本地存储限制 2025-06-12 23:50:24 +08:00
keven
c971e92905 chore: 移除不再使用的依赖项,包括 go-socket.io 和其他间接依赖,以优化项目的依赖管理 2025-06-12 22:48:06 +08:00
keven1024
a484f8926b refactor: update import paths to use alias and improve layout in result components for better readability 2025-06-08 17:53:26 +08:00
keven1024
bee32be989 feat: add QR code generation component and enhance file sharing result display with improved information layout 2025-06-08 17:39:13 +08:00
keven1024
ba7a648cbe refactor: enhance file sharing functionality by implementing token caching and improving error handling in download processes 2025-06-08 16:23:14 +08:00
keven1024
a0de112853 feat: add error component with localized back to home button for improved user experience 2025-06-06 20:23:06 +08:00
keven1024
ddcf53d456 fix: update default layout image source to a new dynamic URL for improved content delivery 2025-06-06 20:01:45 +08:00
keven1024
bbd451f027 fix: remove husky postinstall script from package.json and update dependencies in pnpm-lock.yaml for improved compatibility 2025-06-03 14:41:00 +08:00
keven1024
edf0fe471d fix: update package.json dependencies and refactor share composables for improved functionality 2025-06-03 14:30:41 +08:00
keven1024
3eee404868 fix: update Dockerfile to install dependencies before deploying frontend, and remove project title and description from environment variables 2025-06-03 11:40:54 +08:00
32 changed files with 3725 additions and 2254 deletions

View File

@@ -17,7 +17,8 @@ steps:
- ${DRONE_TAG} - ${DRONE_TAG}
- latest - latest
build_args: build_args:
- BUILD_TAG=${DRONE_TAG} - VERSION=${DRONE_TAG}
- BUILD_TIME=${DRONE_BUILD_FINISHED}
- name: build-worker - name: build-worker
image: plugins/docker image: plugins/docker
settings: settings:

9
.prettierrc Normal file
View File

@@ -0,0 +1,9 @@
{
"trailingComma": "es5",
"tabWidth": 4,
"semi": false,
"singleQuote": true,
"printWidth": 150,
"jsxBracketSameLine": false,
"bracketSameLine": false
}

View File

@@ -2,10 +2,10 @@ FROM node:22-alpine AS front-base
# Install dependencies only when needed # Install dependencies only when needed
FROM front-base AS front-deps FROM front-base AS front-deps
RUN apk add --no-cache libc6-compat RUN apk add --no-cache gcompat
WORKDIR /app WORKDIR /app
COPY . . COPY . .
RUN corepack enable pnpm && pnpm --filter=015-front deploy dist RUN corepack enable pnpm && pnpm i && pnpm --filter=015-front deploy dist
FROM front-base AS front-builder FROM front-base AS front-builder
@@ -26,7 +26,8 @@ RUN CGO_ENABLED=0 GOOS=linux go build -o backend
FROM front-base AS runner FROM front-base AS runner
ARG BUILD_TAG ARG VERSION
ARG BUILD_TIME
WORKDIR /app WORKDIR /app
RUN apk add --no-cache curl openssl RUN apk add --no-cache curl openssl
ENV NODE_ENV production ENV NODE_ENV production
@@ -41,8 +42,10 @@ COPY 015.sh /app/015.sh
# Change the port and host # Change the port and host
ENV PORT=80 HOST=0.0.0.0 ENV PORT=80 HOST=0.0.0.0
ENV SITE_URL="http://localhost" SITE_TITLE="015" SITE_DESC="015 是一个开源的临时内容分享平台项目, 支持文件和文本上传, 下载, 分享" ENV SITE_URL="http://localhost"
ENV UPLOAD_PATH="/uploads" ENV UPLOAD_PATH="/uploads"
ENV VERSION=${VERSION}
ENV BUILD_TIME=${BUILD_TIME}
EXPOSE 80 EXPOSE 80

View File

@@ -1,3 +1,20 @@
# 015 # 015
这里是send企划 这里是send企划
功能:
- ✅ 前端计算hash和秒传
- ✅ 并发切片上传 (使用webWorker计算)
- ✅ 文件上传/文本上传和分享
- ✅ 上传统计页面
- ✅ 多语言支持
- ✅ 最大上传限制
- ✅ 后端有队列系统和worker处理文件
todo:
- 断点续传(后端计算已上传部分并返回)
- 图片格式转换 压缩
- 图片ocr 复制
- xx转markdown
- 文本翻译/总结
- 支持上传多文件

View File

@@ -6,7 +6,6 @@ require (
dario.cat/mergo v1.0.1 dario.cat/mergo v1.0.1
github.com/dustin/go-humanize v1.0.1 github.com/dustin/go-humanize v1.0.1
github.com/golang-jwt/jwt/v5 v5.2.2 github.com/golang-jwt/jwt/v5 v5.2.2
github.com/googollee/go-socket.io v1.7.0
github.com/gorilla/sessions v1.4.0 github.com/gorilla/sessions v1.4.0
github.com/hibiken/asynq v0.25.1 github.com/hibiken/asynq v0.25.1
github.com/labstack/echo-contrib v0.17.3 github.com/labstack/echo-contrib v0.17.3
@@ -24,13 +23,10 @@ require (
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
github.com/gofrs/uuid v4.0.0+incompatible // indirect
github.com/gomodule/redigo v1.8.4 // indirect
github.com/google/go-cmp v0.7.0 // indirect github.com/google/go-cmp v0.7.0 // indirect
github.com/google/uuid v1.6.0 // indirect github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/context v1.1.2 // indirect github.com/gorilla/context v1.1.2 // indirect
github.com/gorilla/securecookie v1.1.2 // indirect github.com/gorilla/securecookie v1.1.2 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/labstack/gommon v0.4.2 // indirect github.com/labstack/gommon v0.4.2 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-isatty v0.0.20 // indirect

View File

@@ -6,7 +6,6 @@ github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
@@ -19,28 +18,20 @@ github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/
github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss= github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss=
github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw=
github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8= github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8=
github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/gomodule/redigo v1.8.4 h1:Z5JUg94HMTR1XpwBaSH4vq3+PNSIykBLxMdglbw10gg=
github.com/gomodule/redigo v1.8.4/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googollee/go-socket.io v1.7.0 h1:ODcQSAvVIPvKozXtUGuJDV3pLwdpBLDs1Uoq/QHIlY8=
github.com/googollee/go-socket.io v1.7.0/go.mod h1:0vGP8/dXR9SZUMMD4+xxaGo/lohOw3YWMh2WRiWeKxg=
github.com/gorilla/context v1.1.2 h1:WRkNAv2uoa03QNIc1A6u4O7DAGMUVoopZhkiXWA2V1o= github.com/gorilla/context v1.1.2 h1:WRkNAv2uoa03QNIc1A6u4O7DAGMUVoopZhkiXWA2V1o=
github.com/gorilla/context v1.1.2/go.mod h1:KDPwT9i/MeWHiLl90fuTgrt4/wPcv75vFAZLaOOcbxM= github.com/gorilla/context v1.1.2/go.mod h1:KDPwT9i/MeWHiLl90fuTgrt4/wPcv75vFAZLaOOcbxM=
github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kXD8ePA= github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kXD8ePA=
github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pwzwo4h3eOamfo= github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pwzwo4h3eOamfo=
github.com/gorilla/sessions v1.4.0 h1:kpIYOp/oi6MG/p5PgxApU8srsSw9tuFbt46Lt7auzqQ= github.com/gorilla/sessions v1.4.0 h1:kpIYOp/oi6MG/p5PgxApU8srsSw9tuFbt46Lt7auzqQ=
github.com/gorilla/sessions v1.4.0/go.mod h1:FLWm50oby91+hl7p/wRxDth9bWSuk0qVL2emc7lT5ik= github.com/gorilla/sessions v1.4.0/go.mod h1:FLWm50oby91+hl7p/wRxDth9bWSuk0qVL2emc7lT5ik=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/hibiken/asynq v0.25.1 h1:phj028N0nm15n8O2ims+IvJ2gz4k2auvermngh9JhTw= github.com/hibiken/asynq v0.25.1 h1:phj028N0nm15n8O2ims+IvJ2gz4k2auvermngh9JhTw=
github.com/hibiken/asynq v0.25.1/go.mod h1:pazWNOLBu0FEynQRBvHA26qdIKRSmfdIfUm4HdsLmXg= github.com/hibiken/asynq v0.25.1/go.mod h1:pazWNOLBu0FEynQRBvHA26qdIKRSmfdIfUm4HdsLmXg=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
@@ -85,8 +76,6 @@ github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.20.1 h1:ZMi+z/lvLyPSCoNtFCpqjy0S4kPbirhpTMwl8BkW9X4= github.com/spf13/viper v1.20.1 h1:ZMi+z/lvLyPSCoNtFCpqjy0S4kPbirhpTMwl8BkW9X4=
github.com/spf13/viper v1.20.1/go.mod h1:P9Mdzt1zoHIG8m2eZQinpiBjo6kCmZSKBClNNqjJvu4= github.com/spf13/viper v1.20.1/go.mod h1:P9Mdzt1zoHIG8m2eZQinpiBjo6kCmZSKBClNNqjJvu4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
@@ -117,7 +106,5 @@ google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojt
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -40,6 +40,27 @@ func CreateUploadTask(c echo.Context) error {
"chunk_size": fileInfo.ChunkSize, "chunk_size": fileInfo.ChunkSize,
}) })
} }
maxStorageSize, err := utils.GetFileSize(utils.GetEnv("MAX_LOCALSTORAGE_SIZE"))
if err != nil {
return utils.HTTPErrorHandler(c, err)
}
fileInfoMap, err := models.GetRedisFileInfoAll()
if err != nil {
return utils.HTTPErrorHandler(c, err)
}
totalSize := int64(0)
for _, value := range fileInfoMap {
var fileInfo models.RedisFileInfo
err := json.Unmarshal([]byte(value), &fileInfo)
if err != nil {
return utils.HTTPErrorHandler(c, err)
}
totalSize += fileInfo.FileSize
}
if totalSize+r.FileSize > int64(maxStorageSize) {
return utils.HTTPErrorHandler(c, errors.New("存储空间不足"))
}
ChunkSize := int64(1 * 1024 * 1024) ChunkSize := int64(1 * 1024 * 1024)
if r.FileSize > 500*1024*1024 { if r.FileSize > 500*1024*1024 {
ChunkSize = r.FileSize / 500 ChunkSize = r.FileSize / 500
@@ -56,7 +77,7 @@ func CreateUploadTask(c echo.Context) error {
CreatedAt: time.Now().Unix(), CreatedAt: time.Now().Unix(),
Expire: uploadTaskExpire, Expire: uploadTaskExpire,
} }
err := models.SetRedisFileInfo(fileId, newFileInfo) err = models.SetRedisFileInfo(fileId, newFileInfo)
if err != nil { if err != nil {
return utils.HTTPErrorHandler(c, err) return utils.HTTPErrorHandler(c, err)
} }

View File

@@ -9,6 +9,7 @@ import (
"github.com/hibiken/asynq" "github.com/hibiken/asynq"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"github.com/samber/lo" "github.com/samber/lo"
"github.com/spf13/cast"
) )
type FileChartData struct { type FileChartData struct {
@@ -83,7 +84,8 @@ func GetStat(c echo.Context) error {
}) })
return utils.HTTPSuccessHandler(c, map[string]any{ return utils.HTTPSuccessHandler(c, map[string]any{
"version": "0.1.0", "version": utils.GetEnvWithDefault("VERSION", "dev"),
"build_time": cast.ToInt(utils.GetEnvWithDefault("BUILD_TIME", cast.ToString(time.Now().Unix()))),
"max_limit": map[string]any{ "max_limit": map[string]any{
"file_size": maxStorageSize, "file_size": maxStorageSize,
}, },

View File

@@ -50,7 +50,7 @@
--card-foreground: oklch(0.129 0.042 264.695); --card-foreground: oklch(0.129 0.042 264.695);
--popover: oklch(1 0 0); --popover: oklch(1 0 0);
--popover-foreground: oklch(0.129 0.042 264.695); --popover-foreground: oklch(0.129 0.042 264.695);
--primary: oklch(0.208 0.042 265.755); --primary: oklch(0.4349 0.0673 257.47);
--primary-foreground: oklch(0.984 0.003 247.858); --primary-foreground: oklch(0.984 0.003 247.858);
--secondary: oklch(0.968 0.007 247.896); --secondary: oklch(0.968 0.007 247.896);
--secondary-foreground: oklch(0.208 0.042 265.755); --secondary-foreground: oklch(0.208 0.042 265.755);

View File

@@ -0,0 +1,20 @@
<script setup lang="ts">
import QRCode from "qrcode";
const props = defineProps<{
hide: () => void;
data: any;
}>();
const { state } = useAsyncState(async () => {
return await QRCode.toDataURL(props.data);
}, null);
</script>
<template>
<div class="flex flex-col gap-5">
<div class="text-xl font-bold">分享二维码</div>
<div class="flex flex-row justify-center">
<img :src="state" v-if="!!state" />
<Skeleton class="size-20" v-else />
</div>
</div>
</template>

View File

@@ -1,11 +1,13 @@
<script lang="ts" setup> <script lang="ts" setup>
import CircularProgress from '@/components/CircularProgress.vue' import CircularProgress from '@/components/CircularProgress.vue'
import { chunk, shuffle, times } from 'lodash-es'; import { chunk, get, shuffle, times } from 'lodash-es'
import { cx } from 'class-variance-authority' import { cx } from 'class-variance-authority'
import calcFileHash from '@/lib/calcFileHash'; import { filesize } from 'filesize'
import { filesize } from 'filesize'; import { toast } from 'vue-sonner'
import asyncWorker from '~/lib/asyncWorker'
import calcFileHashWorker from '~/lib/calcFileHashWorker?worker'
const props = defineProps<{ const props = defineProps<{
data: { file: File, config: any, handle_type: string } data: { file: File; config: any; handle_type: string }
}>() }>()
const emit = defineEmits<{ const emit = defineEmits<{
@@ -17,21 +19,24 @@ const form = useFormContext()
const step = ref<'hash' | 'upload'>('hash') const step = ref<'hash' | 'upload'>('hash')
const calcHashTime = ref(0) const calcHashTime = ref(0)
const chunkSize = ref(0) const chunkSize = ref(0)
const fileSliceUploadStatusList = ref<{ const fileSliceUploadStatusList = ref<
status: string {
index: number status: string
}[]>([]) index: number
}[]
>([])
const successCount = computed(() => fileSliceUploadStatusList.value.filter((item) => item.status === 'success').length) const successCount = computed(() => fileSliceUploadStatusList.value.filter((item) => item.status === 'success').length)
const alreadyUploadSize = computed(() => successCount.value * chunkSize.value) const alreadyUploadSize = computed(() => successCount.value * chunkSize.value)
const uploadProgress = computed(() => Math.round(alreadyUploadSize.value / (props?.data?.file?.size || 0) * 100)) const uploadProgress = computed(() => Math.round((alreadyUploadSize.value / (props?.data?.file?.size || 0)) * 100))
useAsyncState(async () => { const { error } = useAsyncState(async () => {
const { file } = props.data || {} const { file } = props.data || {}
if (!file) return if (!file) return
const { size, type } = file || {} const { size, type = 'application/octet-stream' } = file || {}
const now = Date.now() const now = Date.now()
const hash = await calcFileHash({ file }) const res = await asyncWorker(calcFileHashWorker, { data: { file } })
const { hash } = res?.data || {}
if (hash) { if (hash) {
step.value = 'upload' step.value = 'upload'
calcHashTime.value = Date.now() - now calcHashTime.value = Date.now() - now
@@ -47,70 +52,72 @@ useAsyncState(async () => {
method: 'POST', method: 'POST',
body: { body: {
size, size,
mime_type: type, mime_type: get(type, '', 'application/octet-stream'),
hash, hash,
} },
}) })
const { id, chunk_size, type: createType } = createData?.data || {} const { id, chunk_size, type: createType } = createData?.data || {}
if (createType !== 'init') { if (createType !== 'init') {
// 文件存在 // 文件存在
form.setFieldValue('file_id', id) form.setFieldValue('file_id', id)
emit('change', 'result') emit('change', 'result')
return; return
} }
chunkSize.value = chunk_size chunkSize.value = chunk_size
const chunks = Math.ceil(size / chunk_size); const chunks = Math.ceil(size / chunk_size)
fileSliceUploadStatusList.value = times(chunks, (i) => ({ fileSliceUploadStatusList.value = times(chunks, (i) => ({
status: 'pending', status: 'pending',
index: i index: i,
})) }))
const readChunk = (start: number): Promise<ArrayBuffer> => { const readChunk = (start: number): Promise<ArrayBuffer> => {
const fileReader = new FileReader(); const fileReader = new FileReader()
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const chunk = file.slice(start, start + chunk_size); const chunk = file.slice(start, start + chunk_size)
fileReader.onload = (e) => resolve(e.target?.result as ArrayBuffer); fileReader.onload = (e) => resolve(e.target?.result as ArrayBuffer)
fileReader.onerror = reject; fileReader.onerror = reject
fileReader.readAsArrayBuffer(chunk); fileReader.readAsArrayBuffer(chunk)
}); })
}; }
const chunkedUploadTasks = chunk(shuffle([...fileSliceUploadStatusList.value]), 3) const chunkedUploadTasks = chunk(shuffle([...fileSliceUploadStatusList.value]), 3)
for (let i = 0; i < chunkedUploadTasks?.length; i++) { for (let i = 0; i < chunkedUploadTasks?.length; i++) {
await Promise.all(chunkedUploadTasks?.[i]?.map(async (item: any) => { await Promise.all(
const { index } = item || {} chunkedUploadTasks?.[i]?.map(async (item: any) => {
try { const { index } = item || {}
const chunk = await readChunk(index * chunk_size); try {
// console.log('chunk', chunk) const chunk = await readChunk(index * chunk_size)
const formData = new FormData() // console.log('chunk', chunk)
formData.append('file', new Blob([chunk])) const formData = new FormData()
formData.append('index', index + 1) formData.append('file', new Blob([chunk]))
formData.append('id', id) formData.append('index', index + 1)
fileSliceUploadStatusList.value[index].status = 'uploading' formData.append('id', id)
const res = await $fetch<{ fileSliceUploadStatusList.value[index].status = 'uploading'
code: number const res = await $fetch<{
}>('/api/file/slice', { code: number
method: 'POST', }>('/api/file/slice', {
body: formData method: 'POST',
}) body: formData,
const { code } = res || {} })
if (code !== 200) { const { code } = res || {}
throw new Error('上传失败') if (code !== 200) {
throw new Error('上传失败')
}
fileSliceUploadStatusList.value[index].status = 'success'
} catch (error) {
console.log('error', error)
// fileSliceStatusList.value[index].status = 'error'
} }
fileSliceUploadStatusList.value[index].status = 'success' })
} catch (error) { )
console.log('error', error)
// fileSliceStatusList.value[index].status = 'error'
}
}))
} }
const r = await $fetch<{ const r = await $fetch<{
code: number code: number
}>('/api/file/finish', { }>('/api/file/finish', {
method: 'POST', method: 'POST',
body: { body: {
id id,
} },
}) })
if (r?.code !== 200) { if (r?.code !== 200) {
throw new Error('上传失败') throw new Error('上传失败')
@@ -118,13 +125,19 @@ useAsyncState(async () => {
form.setFieldValue('file_id', id) form.setFieldValue('file_id', id)
emit('change', 'result') emit('change', 'result')
}, null) }, null)
watch(error, (newVal) => {
if (newVal) {
toast.error('上传失败')
}
emit('change', 'input')
})
</script> </script>
<template> <template>
<div class="flex flex-col gap-3"> <div class="flex flex-col gap-3">
<div class="text-xl font-normal">正在上传</div> <div class="text-xl font-normal">正在上传</div>
<div class="flex flex-col items-center gap-4 md:flex-row md:justify-evenly"> <div class="flex flex-col items-center gap-4 md:flex-row md:justify-evenly">
<div :class="cx('flex flex-row items-center gap-5', step !== 'hash' && 'opacity-50')"> <div :class="cx('flex flex-row items-center gap-5', step !== 'hash' && 'opacity-50')">
<div class="flex flex-col gap-0.5 items-center"> <div class="flex flex-col gap-0.5 items-center">
<div class="text-xs opacity-50">1.计算hash</div> <div class="text-xs opacity-50">1.计算hash</div>
<div class="text-3xl font-light"> <div class="text-3xl font-light">
@@ -138,21 +151,30 @@ useAsyncState(async () => {
<div class="flex flex-col gap-0.5 items-center"> <div class="flex flex-col gap-0.5 items-center">
<div class="text-xs opacity-50">2.上传文件</div> <div class="text-xs opacity-50">2.上传文件</div>
<div class="text-3xl font-light">{{ step !== 'upload' ? 0 : uploadProgress }}%</div> <div class="text-3xl font-light">{{ step !== 'upload' ? 0 : uploadProgress }}%</div>
<div class="text-sm opacity-50" v-if="alreadyUploadSize">{{ filesize(alreadyUploadSize) }} / {{ filesize(data?.file?.size) }}</div> <div class="text-sm opacity-50" v-if="alreadyUploadSize">
{{ filesize(alreadyUploadSize) }} / {{ filesize(data?.file?.size) }}
</div>
</div> </div>
</div> </div>
</div> </div>
<div class="flex flex-row gap-2 items-baseline"> <div class="flex flex-row gap-2 items-baseline">
<div class="text-md font-normal">详细信息</div> <div class="text-md font-normal">详细信息</div>
<div class="text-xs opacity-50" v-if="step === 'upload' && fileSliceUploadStatusList?.length > 0">当前正在上传分块{{ `${successCount}/${Math.ceil(data?.file?.size / chunkSize)}` }} 并发:3</div> <div class="text-xs opacity-50" v-if="step === 'upload' && fileSliceUploadStatusList?.length > 0">
当前正在上传分块{{ `${successCount}/${Math.ceil(data?.file?.size / chunkSize)}` }} 并发:3
</div>
</div> </div>
<div class="flex flex-row flex-wrap gap-1"> <div class="flex flex-row flex-wrap gap-1">
<div v-for="i in fileSliceUploadStatusList" :class="cx('rounded size-4 ', <div
i.status === 'pending' && 'bg-white/90', v-for="i in fileSliceUploadStatusList"
i.status === 'uploading' && 'bg-yellow-500', :class="
i.status === 'success' && 'bg-green-500', cx(
)" /> 'rounded size-4 ',
i.status === 'pending' && 'bg-white/90',
i.status === 'uploading' && 'bg-yellow-500',
i.status === 'success' && 'bg-green-500'
)
"
/>
</div> </div>
</div> </div>
</template>
</template>

View File

@@ -5,14 +5,23 @@ import { Input } from "@/components/ui/input";
import { useClipboard } from "@vueuse/core"; import { useClipboard } from "@vueuse/core";
import { toast } from "vue-sonner"; import { toast } from "vue-sonner";
import { useQuery } from "@tanstack/vue-query"; import { useQuery } from "@tanstack/vue-query";
import useAppShare from "@/composables/useShare"; import useMyAppShare from "@/composables/useMyAppShare";
import useMyAppConfig from "@/composables/useMyAppConfig";
import dayjs from "dayjs";
import relativeTime from "dayjs/plugin/relativeTime";
import "dayjs/locale/zh-cn"; // 导入中文语言包
import showDrawer from "@/lib/showDrawer";
import QrCoreDrawer from "@/components/Drawer/QrCoreDrawer.vue";
dayjs.extend(relativeTime); // 扩展 relativeTime 插件
dayjs.locale("zh-cn"); // 设置语言为中文
const props = defineProps<{ const props = defineProps<{
data: { file: File; config: any; handle_type: string; file_id: string }; data: { file: File; config: any; handle_type: string; file_id: string };
}>(); }>();
const emit = defineEmits<{ const emit = defineEmits<{
(e: "change", key: string): void; (e: "change", key: string): void;
}>(); }>();
const { createFileShare } = useAppShare(); const { createFileShare } = useMyAppShare();
const { data } = useQuery({ const { data } = useQuery({
queryKey: ["create-share", props?.data?.file_id], queryKey: ["create-share", props?.data?.file_id],
queryFn: async () => { queryFn: async () => {
@@ -27,7 +36,7 @@ const { data } = useQuery({
}, },
}); });
const appConfig = useAppConfig(); const appConfig = useMyAppConfig();
const url = computed(() => { const url = computed(() => {
const { id } = data?.value || {}; const { id } = data?.value || {};
return `${appConfig?.value?.site_url}/s/${id}`; return `${appConfig?.value?.site_url}/s/${id}`;
@@ -43,28 +52,92 @@ const { copy } = useClipboard();
<div class="flex flex-col h-30 items-center"> <div class="flex flex-col h-30 items-center">
<FilePreviewView :value="props?.data?.file" /> <FilePreviewView :value="props?.data?.file" />
</div> </div>
<div class="flex flex-row gap-2"> <div
<Input v-model="url" class="bg-white/70" /> class="flex flex-col md:flex-row gap-5 rounded-md p-5 bg-white/20 backdrop-blur-xl w-full"
<Button >
variant="outline" <div class="flex flex-col gap-2 flex-1">
class="bg-white/70" <div class="text-sm font-semibold">信息</div>
size="icon" <div class="grid grid-cols-2 gap-2">
@click=" <div class="rounded-xl flex flex-col bg-black/10 px-3 py-2 gap-1">
() => { <div class="text-xs font-semibold">下载次数</div>
copy(url); <div class="text-3xl font-light">{{ data?.download_nums }}</div>
toast.success('复制成功'); </div>
} <div class="rounded-xl flex flex-col bg-black/5 px-3 py-2 gap-1">
" <div class="text-xs font-semibold">过期时间</div>
> <div class="text-md font-light">
<LucideCopy /> {{
</Button> dayjs(data?.expire_at * 1000).format("YYYY-MM-DD HH:mm:ss")
}}
</div>
</div>
<div
class="rounded-xl flex flex-col bg-black/10 px-3 py-2 gap-1"
v-if="data?.pickup_code"
>
<div class="flex flex-row justify-between w-full items-center">
<div class="text-xs font-semibold">提取码</div>
<Button
variant="outline"
class="bg-white/70 p-0 size-6"
size="icon"
@click="
() => {
copy(data?.pickup_code);
toast.success('复制成功');
}
"
>
<LucideCopy class="size-3" />
</Button>
</div>
<div class="flex flex-row gap-2">
<div v-for="s in data?.pickup_code" class="text-2xl font-light">
{{ s }}
</div>
</div>
</div>
</div>
</div>
<div class="flex flex-col gap-5 flex-1">
<div class="text-sm font-semibold">链接</div>
<div class="flex flex-row gap-2">
<Input v-model="url" class="bg-white/70" readonly />
<Button
variant="outline"
class="bg-white/70"
size="icon"
@click="
() => {
copy(url);
toast.success('复制成功');
}
"
>
<LucideCopy />
</Button>
<Button variant="outline" class="bg-white/70" size="icon"> <Button
<LucideQrCode /> variant="outline"
</Button> class="bg-white/70"
size="icon"
@click="
() => {
showDrawer({
render: ({ ...rest }) =>
h(QrCoreDrawer, {
...rest,
data: url,
}),
});
}
"
>
<LucideQrCode />
</Button>
</div>
</div>
</div> </div>
<Button <Button
variant="ghost"
class="hover:bg-white/50 w-40" class="hover:bg-white/50 w-40"
@click=" @click="
() => { () => {

View File

@@ -3,7 +3,7 @@ import { useQuery } from "@tanstack/vue-query";
import { AsyncButton, Button } from "@/components/ui/button"; import { AsyncButton, Button } from "@/components/ui/button";
import { Skeleton } from "@/components/ui/skeleton"; import { Skeleton } from "@/components/ui/skeleton";
import { filesize } from "filesize"; import { filesize } from "filesize";
import useAppShare from "~/composables/useShare"; import useMyAppShare from "@/composables/useMyAppShare";
import { toast } from "vue-sonner"; import { toast } from "vue-sonner";
const emit = defineEmits<{ const emit = defineEmits<{
(e: "change", key: string): void; (e: "change", key: string): void;
@@ -63,7 +63,7 @@ const { data: taskData, refetch } = useQuery({
enabled: !!taskId.value, enabled: !!taskId.value,
}); });
const { downloadFile, createFileShare } = useAppShare(); const { downloadFile, createFileShare } = useMyAppShare();
const { counter, pause } = useInterval(2000, { controls: true }); const { counter, pause } = useInterval(2000, { controls: true });

View File

@@ -4,7 +4,10 @@ import { Input } from "@/components/ui/input";
import { useClipboard } from "@vueuse/core"; import { useClipboard } from "@vueuse/core";
import { toast } from "vue-sonner"; import { toast } from "vue-sonner";
import { useQuery } from "@tanstack/vue-query"; import { useQuery } from "@tanstack/vue-query";
import useAppShare from "@/composables/useShare"; import useMyAppShare from "@/composables/useMyAppShare";
import useMyAppConfig from "@/composables/useMyAppConfig";
import showDrawer from "@/lib/showDrawer";
import QrCoreDrawer from "@/components/Drawer/QrCoreDrawer.vue";
const props = defineProps<{ const props = defineProps<{
data: { text: string; config: any; handle_type: string }; data: { text: string; config: any; handle_type: string };
@@ -14,7 +17,7 @@ const emit = defineEmits<{
(e: "change", key: string): void; (e: "change", key: string): void;
}>(); }>();
const { createTextShare } = useAppShare(); const { createTextShare } = useMyAppShare();
const { data } = useQuery({ const { data } = useQuery({
queryKey: ["create-share", props?.data?.text], queryKey: ["create-share", props?.data?.text],
queryFn: async () => { queryFn: async () => {
@@ -26,7 +29,7 @@ const { data } = useQuery({
return data?.data; return data?.data;
}, },
}); });
const appConfig = useAppConfig(); const appConfig = useMyAppConfig();
const url = computed(() => { const url = computed(() => {
const { id } = data?.value || {}; const { id } = data?.value || {};
return `${appConfig?.value?.site_url}/s/${id}`; return `${appConfig?.value?.site_url}/s/${id}`;
@@ -37,9 +40,9 @@ const { copy } = useClipboard();
<template> <template>
<div class="flex flex-col gap-3"> <div class="flex flex-col gap-3">
<div class="flex flex-row justify-between"> <div class="flex flex-col md:flex-row gap-2">
<h2 class="text-lg">分享成功</h2> <div class="flex flex-row justify-between md:basis-1/2">
<div class="flex flex-row gap-2 basis-1/2"> <h2 class="text-lg">分享成功</h2>
<Button <Button
variant="outline" variant="outline"
class="bg-white/70" class="bg-white/70"
@@ -52,7 +55,9 @@ const { copy } = useClipboard();
> >
<LucideHome /> <LucideHome />
</Button> </Button>
<Input v-model="url" class="bg-white/70" /> </div>
<div class="flex flex-row gap-2 flex-1">
<Input v-model="url" class="bg-white/70" readonly />
<Button <Button
variant="outline" variant="outline"
class="bg-white/70" class="bg-white/70"
@@ -66,13 +71,28 @@ const { copy } = useClipboard();
> >
<LucideCopy /> <LucideCopy />
</Button> </Button>
<Button variant="outline" class="bg-white/70" size="icon"> <Button
variant="outline"
class="bg-white/70"
size="icon"
@click="
() => {
showDrawer({
render: ({ ...rest }) =>
h(QrCoreDrawer, {
...rest,
data: url,
}),
});
}
"
>
<LucideQrCode /> <LucideQrCode />
</Button> </Button>
</div> </div>
</div> </div>
<div <div
class="prose rounded-md bg-white/70 p-3 w-full max-w-full" class="prose rounded-md bg-white/70 p-3 w-full max-w-full min-h-[30vh]"
v-html="props?.data?.text" v-html="props?.data?.text"
/> />
</div> </div>

View File

@@ -1,73 +1,69 @@
<script setup lang="ts"> <script setup lang="ts">
import AsyncButton from '@/components/ui/button/AsyncButton.vue' import AsyncButton from "@/components/ui/button/AsyncButton.vue";
import dayjs from 'dayjs'; import dayjs from "dayjs";
import duration from 'dayjs/plugin/duration'; import duration from "dayjs/plugin/duration";
import relativeTime from 'dayjs/plugin/relativeTime'; import relativeTime from "dayjs/plugin/relativeTime";
import { isBoolean } from 'lodash-es'; import { isBoolean } from "lodash-es";
import { LucideCheck, LucideX } from 'lucide-vue-next'; import { LucideCheck, LucideX } from "lucide-vue-next";
import { useQueryClient } from '@tanstack/vue-query'; import { useQueryClient } from "@tanstack/vue-query";
dayjs.extend(duration) dayjs.extend(duration);
dayjs.extend(relativeTime) dayjs.extend(relativeTime);
const props = defineProps<{ const props = defineProps<{
data: any data: any;
}>() }>();
const queryClient = useQueryClient() const queryClient = useQueryClient();
const { downloadFile } = useMyAppShare();
const handleDownload = async () => { const handleDownload = async () => {
const { id } = props?.data || {} const { id } = props?.data || {};
const data = await $fetch<{ await downloadFile(id);
code: number queryClient.invalidateQueries({ queryKey: ["share", id] });
data: { };
token?: string
}
}>(`/api/download`, {
method: 'POST',
body: {
share_id: id
}
})
const { token } = data?.data || {}
if (!token) {
return
}
(window as any)?.open(`/api/download?token=${token}`)
queryClient.invalidateQueries({ queryKey: ['share', id] })
}
const expireSeconds = computed(() => { const expireSeconds = computed(() => {
return dayjs(props?.data?.expire_at * 10e2).unix() - dayjs().unix() return dayjs(props?.data?.expire_at * 10e2).unix() - dayjs().unix();
}) });
const { remaining, start} = useCountdown(expireSeconds.value) const { remaining, start } = useCountdown(expireSeconds.value);
onMounted(() => { onMounted(() => {
start() start();
}) });
const fileShareInfo = computed(() => { const fileShareInfo = computed(() => {
return [ return [
{ label: '需要密码', value: props?.data?.has_password ?? false }, { label: "需要密码", value: props?.data?.has_password ?? false },
{ label: '过期时间', value: dayjs.duration(remaining.value, 'seconds').format(`D天 HH:mm:ss`) }, {
{ label: '剩余下载次数', value: props?.data?.download_nums ?? 0 }, label: "过期时间",
] value: dayjs.duration(remaining.value, "seconds").format(`D天 HH:mm:ss`),
}) },
{ label: "剩余下载次数", value: props?.data?.download_nums ?? 0 },
];
});
</script> </script>
<template> <template>
<div class="flex flex-col gap-5 items-center"> <div class="flex flex-col gap-5 items-center">
<h1 class="text-xl font-bold">下载文件</h1> <h1 class="text-xl font-bold">下载文件</h1>
<FilePreviewView :value="props?.data" /> <FilePreviewView :value="props?.data" />
<div class="flex flex-col gap-2 md:flex-row w-full"> <div class="flex flex-col gap-2 md:flex-row w-full">
<div class="flex flex-row md:flex-col md:gap-1 justify-between items-center md:flex-1" v-for="item in fileShareInfo"> <div
<div class="text-xs opacity-75">{{ item?.label }}</div> class="flex flex-row md:flex-col md:gap-1 justify-between items-center md:flex-1"
<component v-if="isBoolean(item?.value)" :is="item?.value ? LucideCheck : LucideX" class="size-6" /> v-for="item in fileShareInfo"
<div v-else class="md:text-xl">{{ item?.value }}</div> >
</div> <div class="text-xs opacity-75">{{ item?.label }}</div>
</div> <component
<div class="w-full"> v-if="isBoolean(item?.value)"
<AsyncButton @click="handleDownload" class="w-full">下载</AsyncButton> :is="item?.value ? LucideCheck : LucideX"
</div> class="size-6"
/>
<div v-else class="md:text-xl">{{ item?.value }}</div>
</div>
</div> </div>
</template> <div class="w-full">
<AsyncButton @click="handleDownload" class="w-full">下载</AsyncButton>
</div>
</div>
</template>

View File

@@ -1,87 +1,93 @@
<script setup lang="ts"> <script setup lang="ts">
import dayjs from 'dayjs'; import dayjs from "dayjs";
import AsyncButton from '@/components/ui/button/AsyncButton.vue' import AsyncButton from "@/components/ui/button/AsyncButton.vue";
import duration from 'dayjs/plugin/duration'; import duration from "dayjs/plugin/duration";
import relativeTime from 'dayjs/plugin/relativeTime'; import relativeTime from "dayjs/plugin/relativeTime";
import { isBoolean } from 'lodash-es'; import { isBoolean } from "lodash-es";
import { LucideCheck, LucideX } from 'lucide-vue-next'; import { LucideCheck, LucideX } from "lucide-vue-next";
import { cx } from 'class-variance-authority'; import { cx } from "class-variance-authority";
import { toast } from 'vue-sonner'; import { toast } from "vue-sonner";
import MarkdownRender from '@/components/MarkdownRender.vue' import MarkdownRender from "@/components/MarkdownRender.vue";
dayjs.extend(duration) dayjs.extend(duration);
dayjs.extend(relativeTime) dayjs.extend(relativeTime);
const props = defineProps<{ const props = defineProps<{
data: any data: any;
}>() }>();
const { getShareToken } = useMyAppShare();
const expireSeconds = computed(() => { const expireSeconds = computed(() => {
return dayjs(props?.data?.expire_at * 10e2).unix() - dayjs().unix() return dayjs(props?.data?.expire_at * 10e2).unix() - dayjs().unix();
}) });
const { remaining, start } = useCountdown(expireSeconds.value) const { remaining, start } = useCountdown(expireSeconds.value);
onMounted(() => { onMounted(() => {
start() start();
}) });
const fileShareInfo = computed(() => { const fileShareInfo = computed(() => {
return [ return [
{ label: '需要密码', value: props?.data?.has_password ?? false }, { label: "需要密码", value: props?.data?.has_password ?? false },
{ label: '过期时间', value: dayjs.duration(remaining.value, 'seconds').format(`D天 HH:mm:ss`) }, {
{ label: '剩余浏览次数', value: props?.data?.download_nums ?? 0 }, label: "过期时间",
] value: dayjs.duration(remaining.value, "seconds").format(`D天 HH:mm:ss`),
}) },
const previewText = ref<string | null>(null) { label: "剩余浏览次数", value: props?.data?.download_nums ?? 0 },
];
});
const previewText = ref<string | null>(null);
const handlePreview = async () => { const handlePreview = async () => {
try { try {
const { id } = props?.data || {} const token = await getShareToken(props?.data?.id);
const data = await $fetch<{ const r = await $fetch<{
code: number code: number;
data: { data: {
token?: string data: string;
} };
}>(`/api/download`, { }>(`/api/download?token=${token}`);
method: 'POST', previewText.value = r?.data?.data;
body: { } catch (error) {
share_id: id toast.error((error as any)?.data?.message || error);
} }
}) };
const { token } = data?.data || {}
if (!token) {
return
}
const r = await $fetch<{
code: number
data: {
data: string
}
}>(`/api/download?token=${token}`)
previewText.value = r?.data?.data
} catch (error) {
toast.error(error?.data?.message || '获取失败')
}
}
</script> </script>
<template> <template>
<div :class="cx('flex flex-col max-h-full', !!previewText ? 'gap-3' : 'gap-16 items-center')"> <div
<h1 class="text-xl">查看文本</h1> :class="
<template v-if="!previewText"> cx(
<div class="flex flex-col gap-2 md:flex-row w-full"> 'flex flex-col max-h-full',
<div class="flex flex-row md:flex-col md:gap-1 justify-between items-center md:flex-1" !!previewText ? 'gap-3' : 'gap-16 items-center',
v-for="item in fileShareInfo"> )
<div class="text-xs opacity-75">{{ item?.label }}</div> "
<component v-if="isBoolean(item?.value)" :is="item?.value ? LucideCheck : LucideX" class="size-6" /> >
<div v-else class="md:text-xl">{{ item?.value }}</div> <h1 class="text-xl">查看文本</h1>
</div> <template v-if="!previewText">
</div> <div class="flex flex-col gap-2 md:flex-row w-full">
<div class="w-full"> <div
<AsyncButton @click="handlePreview" class="w-full">浏览</AsyncButton> class="flex flex-row md:flex-col md:gap-1 justify-between items-center md:flex-1"
</div> v-for="item in fileShareInfo"
</template> >
<template v-else> <div class="text-xs opacity-75">{{ item?.label }}</div>
<MarkdownRender :markdown="previewText" class="rounded-md bg-white/70 p-3 w-full max-w-full min-h-80 overflow-y-auto" /> <component
</template> v-if="isBoolean(item?.value)"
</div> :is="item?.value ? LucideCheck : LucideX"
</template> class="size-6"
/>
<div v-else class="md:text-xl">{{ item?.value }}</div>
</div>
</div>
<div class="w-full">
<AsyncButton @click="handlePreview" class="w-full">浏览</AsyncButton>
</div>
</template>
<template v-else>
<MarkdownRender
:markdown="previewText"
class="rounded-md bg-white/70 p-3 w-full max-w-full min-h-80 overflow-y-auto"
/>
</template>
</div>
</template>

View File

@@ -1,6 +0,0 @@
const useAppConfig = () => {
const { data } = useFetch('/config')
return data
}
export default useAppConfig

View File

@@ -0,0 +1,6 @@
const useMyAppConfig = () => {
const { data } = useFetch("/config");
return data;
};
export default useMyAppConfig;

View File

@@ -0,0 +1,98 @@
import { toast } from "vue-sonner";
let shareIdTokenMap: WeakMap<{ share_id: string }, string>;
const getShareToken = async (share_id: string): Promise<string | undefined> => {
if (!shareIdTokenMap) {
shareIdTokenMap = new WeakMap();
}
let token = shareIdTokenMap.get({ share_id });
if (!token) {
const data = await $fetch<{
code: number;
message: string;
data: {
token?: string;
};
}>(`/api/download`, {
method: "POST",
body: {
share_id,
},
});
if (!data?.data?.token) {
throw new Error(data?.message || "获取token失败");
}
token = data.data.token;
shareIdTokenMap.set({ share_id }, token);
}
return token;
};
const downloadFile = async (share_id: string) => {
try {
const token = await getShareToken(share_id);
if (!token) {
throw new Error("获取token失败");
return;
}
(window as any)?.open(`/api/download?token=${token}`);
} catch (e) {
toast.error((e as any)?.data?.message || e);
}
};
const createShare = async (data: any) => {
return await $fetch<{
code: number;
data: {
id?: string;
};
}>(`/api/share`, {
method: "POST",
body: data,
});
};
const createFileShare = async (data: {
file_id: string;
config: {
download_nums: number;
expire_time: number;
has_pickup_code?: boolean;
has_password?: boolean;
pickup_code?: string;
password?: string;
notify_email?: string;
};
file_name: string;
}) => {
const { file_id, config, file_name } = data || {};
return await createShare({
type: "file",
data: file_id,
config,
file_name,
});
};
const createTextShare = async (data: { text: string; config: any }) => {
const { text, config } = data || {};
return await createShare({
type: "text",
data: text,
config,
});
};
const useMyAppShare = () => {
return {
downloadFile,
createShare,
createFileShare,
createTextShare,
getShareToken,
};
};
export default useMyAppShare;

View File

@@ -1,72 +0,0 @@
const downloadFile = async (share_id: string) => {
const data = await $fetch<{
code: number;
data: {
token?: string;
};
}>(`/api/download`, {
method: "POST",
body: {
share_id,
},
});
const { token } = data?.data || {};
if (!token) {
return;
}
(window as any)?.open(`/api/download?token=${token}`);
};
const createShare = async (data: any) => {
return await $fetch<{
code: number;
data: {
id?: string;
};
}>(`/api/share`, {
method: "POST",
body: data,
});
};
const createFileShare = async (data: {
file_id: string;
config: {
download_nums: number;
expire_time: number;
has_pickup_code?: boolean;
has_password?: boolean;
pickup_code?: string;
password?: string;
notify_email?: string;
};
file_name: string;
}) => {
const { file_id, config, file_name } = data || {};
return await createShare({
type: "file",
data: file_id,
config,
file_name,
});
};
const createTextShare = async (data: { text: string; config: any }) => {
const { text, config } = data || {};
return await createShare({
type: "text",
data: text,
config,
});
};
const useAppShare = () => {
return {
downloadFile,
createShare,
createFileShare,
createTextShare,
};
};
export default useAppShare;

24
front/error.vue Normal file
View File

@@ -0,0 +1,24 @@
<script setup lang="ts">
import type { NuxtError } from "#app";
import { useI18n } from "vue-i18n";
import { Button } from "@/components/ui/button";
const { t } = useI18n();
const props = defineProps({
error: Object as () => NuxtError,
});
const handleError = () => clearError({ redirect: "/" });
</script>
<template>
<NuxtLayout>
<div
class="rounded-xl p-5 bg-white/50 backdrop-blur-xl w-full lg:w-200 flex flex-col items-center justify-center min-h-[50vh] mt-5 gap-10"
>
<div class="font-bold text-5xl">{{ error?.statusCode }}</div>
<Button @click="handleError">{{ t("btn.backToHome") }}</Button>
</div>
</NuxtLayout>
</template>

View File

@@ -10,7 +10,8 @@
"desc": "015 is a temporary file sharing platform project, supporting temporary large file slicing upload, temporary text upload, download and share" "desc": "015 is a temporary file sharing platform project, supporting temporary large file slicing upload, temporary text upload, download and share"
}, },
"btn": { "btn": {
"submit": "Submit" "submit": "Submit",
"backToHome": "Back to Home"
}, },
"file": { "file": {
"uploadFile": "Upload File", "uploadFile": "Upload File",

View File

@@ -10,7 +10,8 @@
"desc": "015 是一个开源的临时文件分享平台项目,支持临时大文件切片上传,临时文本上传、下载、分享" "desc": "015 是一个开源的临时文件分享平台项目,支持临时大文件切片上传,临时文本上传、下载、分享"
}, },
"btn": { "btn": {
"submit": "提交" "submit": "提交",
"backToHome": "返回首页"
}, },
"file": { "file": {
"uploadFile": "上传文件", "uploadFile": "上传文件",

View File

@@ -8,7 +8,7 @@ await useSeo();
<Toaster position="top-center" richColors closeButton /> <Toaster position="top-center" richColors closeButton />
<img <img
class="w-full h-full object-cover absolute inset-0 -z-[1]" class="w-full h-full object-cover absolute inset-0 -z-[1]"
src="https://fuwari.vercel.app/_astro/demo-banner.DFyx781H_Z1gN7UP.webp" src="https://img.fudaoyuan.icu/api/1/random/?scale_min=1.5&webp=true&md=false&format=302"
/> />
<div <div
class="h-full w-full flex flex-col items-center lg:p-10 p-5 overflow-y-auto" class="h-full w-full flex flex-col items-center lg:p-10 p-5 overflow-y-auto"

14
front/lib/asyncWorker.ts Normal file
View File

@@ -0,0 +1,14 @@
const asyncWorker = (w: new () => Worker, opts: { data: any }) => {
const { data } = opts || {}
return new Promise<MessageEvent>((resolve, reject) => {
const worker = new w()
worker.postMessage(data || {})
worker.onmessage = (e: MessageEvent) => {
resolve(e)
}
worker.onerror = (e: ErrorEvent) => {
reject(e)
}
})
}
export default asyncWorker

View File

@@ -1,44 +1,47 @@
import SparkMD5 from 'spark-md5'; import { noop } from 'lodash-es'
import { noop } from 'lodash-es'; import { md5 } from 'js-md5'
interface CalcFileHashProps { interface CalcFileHashProps {
file: File; file: File
onProgress?: (current: number) => void; onProgress?: (current: number) => void
chunkSize?: number; chunkSize?: number
} }
const calcFileHash = async (props: CalcFileHashProps) => { const calcFileHash = async (props: CalcFileHashProps) => {
const { file, onProgress = noop, chunkSize = 100 } = props || {}; const { file, onProgress = noop, chunkSize = 100 } = props || {}
const finalChunkSize = chunkSize * 1024 * 1024; const blob = await file.arrayBuffer()
const chunks = Math.ceil(file.size / finalChunkSize); const hash = md5(blob)
const spark = new SparkMD5.ArrayBuffer(); // 使用 SparkMD5 增量计算哈希 return hash
const fileReader = new FileReader(); // const finalChunkSize = chunkSize * 1024 * 1024;
// const chunks = Math.ceil(file.size / finalChunkSize);
// const spark = new SparkMD5.ArrayBuffer(); // 使用 SparkMD5 增量计算哈希
// const fileReader = new FileReader();
const readChunk = (start: number): Promise<ArrayBuffer> => { // const readChunk = (start: number): Promise<ArrayBuffer> => {
return new Promise((resolve, reject) => { // return new Promise((resolve, reject) => {
const chunk = file.slice(start, start + finalChunkSize); // const chunk = file.slice(start, Math.min(start + finalChunkSize, file.size));
fileReader.onload = (e) => resolve(e.target?.result as ArrayBuffer); // fileReader.onload = (e) => resolve(e.target?.result as ArrayBuffer);
fileReader.onerror = reject; // fileReader.onerror = reject;
fileReader.readAsArrayBuffer(chunk); // fileReader.readAsArrayBuffer(chunk);
}); // });
}; // };
try { // try {
const progressCallback = (current: number) => { // const progressCallback = (current: number) => {
const percentage = Math.round((current / chunks) * 100); // const percentage = Math.round((current / chunks) * 100);
onProgress(percentage); // onProgress(percentage);
}; // };
for (let i = 0; i < chunks; i++) { // for (let i = 0; i < chunks; i++) {
const chunk = await readChunk(i * chunkSize); // const chunk = await readChunk(i * chunkSize);
spark.append(chunk); // spark.append(chunk);
progressCallback(i + 1); // progressCallback(i + 1);
} // }
return spark.end(); // return spark.end();
} catch (error) { // } catch (error) {
throw error; // throw error;
} // }
} }
export default calcFileHash; export default calcFileHash

View File

@@ -0,0 +1,8 @@
import calcFileHash from './calcFileHash'
// 监听主线程消息
self.onmessage = async (e: MessageEvent<{ file: File }>) => {
const { file } = e.data || {}
const hash = await calcFileHash({ file })
self.postMessage({ hash })
}

View File

@@ -3,7 +3,7 @@ import tailwindcss from "@tailwindcss/vite";
export default defineNuxtConfig({ export default defineNuxtConfig({
compatibilityDate: "2024-04-03", compatibilityDate: "2024-04-03",
devtools: { enabled: true }, devtools: { enabled: true },
css: ["~/assets/css/main.css"], css: ["@/assets/css/main.css"],
modules: [ modules: [
// '@serwist/nuxt', // '@serwist/nuxt',
"@vueuse/nuxt", "@vueuse/nuxt",
@@ -35,7 +35,6 @@ export default defineNuxtConfig({
}, },
}, },
devServer: { devServer: {
port: parseInt(process.env.PORT || "5000"), port: 5000,
host: process.env.HOST || "0.0.0.0",
}, },
}); });

View File

@@ -1,71 +1,71 @@
{ {
"name": "015-front", "name": "015-front",
"private": true, "private": true,
"type": "module", "type": "module",
"scripts": { "scripts": {
"build": "nuxt build", "build": "nuxt build",
"dev": "nuxt dev", "dev": "nuxt dev",
"generate": "nuxt generate", "generate": "nuxt generate",
"preview": "nuxt preview", "preview": "nuxt preview",
"postinstall": "nuxt prepare" "postinstall": "nuxt prepare"
}, },
"dependencies": { "dependencies": {
"@nuxt/image": "1.10.0", "@nuxt/image": "1.10.0",
"@nuxtjs/i18n": "9.5.5", "@nuxtjs/i18n": "9.5.5",
"@pinia/nuxt": "^0.11.0", "@pinia/nuxt": "^0.11.0",
"@tailwindcss/postcss": "^4.1.3", "@tailwindcss/postcss": "^4.1.3",
"@tailwindcss/vite": "^4.1.3", "@tailwindcss/vite": "^4.1.3",
"@tanstack/vue-query": "^5.76.0", "@tanstack/vue-query": "^5.76.0",
"@tiptap/extension-blockquote": "^2.11.7", "@tiptap/extension-blockquote": "^2.11.7",
"@tiptap/extension-bold": "^2.11.7", "@tiptap/extension-bold": "^2.11.7",
"@tiptap/extension-heading": "^2.11.7", "@tiptap/extension-heading": "^2.11.7",
"@tiptap/extension-italic": "^2.11.7", "@tiptap/extension-italic": "^2.11.7",
"@tiptap/extension-paragraph": "^2.11.7", "@tiptap/extension-paragraph": "^2.11.7",
"@tiptap/extension-placeholder": "^2.11.7", "@tiptap/extension-placeholder": "^2.11.7",
"@tiptap/extension-strike": "^2.11.7", "@tiptap/extension-strike": "^2.11.7",
"@tiptap/extension-text": "^2.11.7", "@tiptap/extension-text": "^2.11.7",
"@tiptap/pm": "^2.11.7", "@tiptap/pm": "^2.11.7",
"@tiptap/starter-kit": "^2.11.7", "@tiptap/starter-kit": "^2.11.7",
"@tiptap/vue-3": "^2.11.7", "@tiptap/vue-3": "^2.11.7",
"@types/lodash-es": "^4.17.12", "@unovis/ts": "^1.5.1",
"@types/spark-md5": "^3.0.5", "@unovis/vue": "^1.5.1",
"@unovis/ts": "^1.5.1", "@vee-validate/nuxt": "^4.15.0",
"@unovis/vue": "^1.5.1", "@vee-validate/rules": "^4.15.0",
"@vee-validate/nuxt": "^4.15.0", "axios": "^1.8.4",
"@vee-validate/rules": "^4.15.0", "class-variance-authority": "^0.7.1",
"axios": "^1.8.4", "clsx": "^2.1.1",
"class-variance-authority": "^0.7.1", "dayjs": "^1.11.13",
"clsx": "^2.1.1", "filesize": "^10.1.6",
"dayjs": "^1.11.13", "js-md5": "^0.8.3",
"filesize": "^10.1.6", "lodash-es": "^4.17.21",
"lodash-es": "^4.17.21", "lucide-vue-next": "^0.487.0",
"lucide-vue-next": "^0.487.0", "markdown-it": "^14.1.0",
"markdown-it": "^14.1.0", "motion-v": "1.0.0-beta.2",
"motion-v": "1.0.0-beta.2", "nuxt": "^3.17.4",
"nuxt": "^3.16.0", "nuxt-lucide-icons": "1.0.5",
"nuxt-lucide-icons": "1.0.5", "pinia": "^3.0.2",
"reka-ui": "^2.2.0", "qrcode": "^1.5.4",
"shadcn-nuxt": "2.0.1", "reka-ui": "^2.2.0",
"spark-md5": "^3.0.2", "shadcn-nuxt": "2.0.1",
"tailwind-merge": "^3.2.0", "spark-md5": "^3.0.2",
"tailwindcss": "^4.1.3", "tailwind-merge": "^3.2.0",
"tiptap-markdown": "^0.8.10", "tailwindcss": "^4.1.3",
"tw-animate-css": "^1.2.5", "tiptap-markdown": "^0.8.10",
"vaul-vue": "^0.4.1", "tw-animate-css": "^1.2.5",
"vue": "latest", "vaul-vue": "^0.4.1",
"vue-router": "latest", "vue": "^3.5.16",
"vue-sonner": "^1.3.2" "vue-router": "^4.5.1",
}, "vue-sonner": "^1.3.2"
"packageManager": "pnpm@9.11.0+sha512.0a203ffaed5a3f63242cd064c8fb5892366c103e328079318f78062f24ea8c9d50bc6a47aa3567cabefd824d170e78fa2745ed1f16b132e16436146b7688f19b", },
"devDependencies": { "packageManager": "pnpm@9.11.0+sha512.0a203ffaed5a3f63242cd064c8fb5892366c103e328079318f78062f24ea8c9d50bc6a47aa3567cabefd824d170e78fa2745ed1f16b132e16436146b7688f19b",
"@nuxtjs/tailwindcss": "^6.13.2", "devDependencies": {
"@serwist/build": "^9.0.12", "@nuxtjs/tailwindcss": "^6.13.2",
"@serwist/nuxt": "^9.0.12", "@tailwindcss/typography": "^0.5.16",
"@serwist/vite": "^9.0.12", "@types/lodash-es": "^4.17.12",
"@tailwindcss/typography": "^0.5.16", "@types/markdown-it": "^14.1.2",
"@types/markdown-it": "^14.1.2", "@types/qrcode": "^1.5.5",
"@vueuse/core": "^13.0.0", "@types/spark-md5": "^3.0.5",
"@vueuse/nuxt": "^13.0.0", "@vueuse/core": "^13.0.0",
"serwist": "^9.0.12" "@vueuse/nuxt": "^13.0.0"
} }
} }

View File

@@ -1,239 +1,213 @@
<script setup lang="ts"> <script setup lang="ts">
import { CurveType } from "@unovis/ts"; import { CurveType } from '@unovis/ts'
import { AreaChart } from "@/components/ui/chart-area"; import { AreaChart } from '@/components/ui/chart-area'
import { cx } from "class-variance-authority"; import { cx } from 'class-variance-authority'
import { useQuery } from "@tanstack/vue-query"; import { useQuery } from '@tanstack/vue-query'
import { Skeleton } from "@/components/ui/skeleton"; import { Skeleton } from '@/components/ui/skeleton'
import AboutChartTooltip from "@/components/AboutChartTooltip.vue"; import AboutChartTooltip from '@/components/AboutChartTooltip.vue'
import { filesize } from "filesize"; import { filesize } from 'filesize'
import SparkMD5 from "spark-md5"; import SparkMD5 from 'spark-md5'
import useMyAppConfig from '@/composables/useMyAppConfig'
import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
import Progress from '~/components/ui/progress/Progress.vue'
const appConfig = useAppConfig(); dayjs.extend(relativeTime)
const { site_title, site_desc } = appConfig.value || {};
const appConfig = useMyAppConfig()
const { site_title, site_desc } = appConfig.value || {}
const { data, isLoading } = useQuery({ const { data, isLoading } = useQuery({
queryKey: ["stat"], queryKey: ['stat'],
queryFn: async () => { queryFn: async () => {
const data = await $fetch<{ data: any }>("/api/stat"); const data = await $fetch<{ data: any }>('/api/stat')
return data.data; return data.data
}, },
}); })
const { t } = useI18n(); const { t } = useI18n()
const chartTabs = computed(() => { const chartTabs = computed(() => {
return [ return [
{ {
label: t("about.file"), label: t('about.file'),
value: "storage", value: 'storage',
total: total: data.value?.chart?.storage?.reduce((acc: number, curr: { file_size: number; file_num: number }) => acc + curr.file_num, 0) ?? 0,
data.value?.chart?.storage?.reduce( },
(acc: number, curr: { file_size: number; file_num: number }) => {
acc + curr.file_num, label: t('about.task'),
0, value: 'queue',
) ?? 0, total:
}, data.value?.chart?.queue?.reduce(
{ (acc: number, curr: { processed: number; failed: number }) => acc + curr.processed + curr.failed,
label: t("about.task"), 0
value: "queue", ) ?? 0,
total: },
data.value?.chart?.queue?.reduce( ]
(acc: number, curr: { processed: number; failed: number }) => })
acc + curr.processed + curr.failed,
0,
) ?? 0,
},
];
});
const currentFileSize = computed(() => { const currentFileSize = computed(() => {
return ( return data.value?.chart?.storage?.reduce((acc: number, curr: { file_size: number; file_num: number }) => acc + curr.file_size, 0) ?? 0
data.value?.chart?.storage?.reduce( })
(acc: number, curr: { file_size: number; file_num: number }) =>
acc + curr.file_size,
0,
) ?? 0
);
});
const currentChartTab = ref<"storage" | "queue">("storage"); const currentChartTab = ref<'storage' | 'queue'>('storage')
const currentChartData = computed(() => { const currentChartData = computed(() => {
const { storage, queue } = data.value?.chart || {}; const { storage, queue } = data.value?.chart || {}
if (currentChartTab.value === "storage") { if (currentChartTab.value === 'storage') {
return {
data: storage,
index: 'date',
categories: ['file_size', 'file_num'],
colors: ['#22d3ee', '#c084fc'],
}
}
return { return {
data: storage, data: queue,
index: "date", index: 'date',
categories: ["file_size", "file_num"], categories: ['processed', 'failed'],
colors: ["#22d3ee", "#c084fc"], colors: ['#4ade80', '#f87171'],
}; }
} })
return {
data: queue,
index: "date",
categories: ["processed", "failed"],
colors: ["#4ade80", "#f87171"],
};
});
const genUserAvatar = ({ email }: { email: string }) => { const genUserAvatar = ({ email }: { email: string }) => {
if (!email) { if (!email) {
return "/logo.png"; return '/logo.png'
} }
return `https://www.gravatar.com/avatar/${SparkMD5.hash(email)}?d=retro`; return `https://www.gravatar.com/avatar/${SparkMD5.hash(email)}?d=retro`
}; }
const handleUserClick = ({ url, email }: { url: string; email: string }) => { const handleUserClick = ({ url, email }: { url: string; email: string }) => {
if (url) { if (url) {
return navigateTo(url, { external: true }); return navigateTo(url, { external: true })
} }
if (email) { if (email) {
return navigateTo(`mailto:${email}`, { external: true }); return navigateTo(`mailto:${email}`, { external: true })
} }
return null; return null
}; }
const users = computed(() => { const users = computed(() => {
const { email, name, url } = data.value?.admin || {}; const { email, name, url } = data.value?.admin || {}
return [ return [
...(!!name ...(!!name
? [ ? [
{ {
title: t("about.admin"), title: t('about.admin'),
email, email,
name, name,
url: url ?? (email ? `mailto:${email}` : null), url: url ?? (email ? `mailto:${email}` : null),
}, },
] ]
: []), : []),
{ {
title: t("about.author"), title: t('about.author'),
name: "keven1024", name: 'keven1024',
email: "keven@fudaoyuan.icu", email: 'keven@fudaoyuan.icu',
url: "https://github.com/keven1024", url: 'https://github.com/keven1024',
}, },
]; ]
}); })
</script> </script>
<template> <template>
<div <div class="rounded-xl p-5 bg-white/50 backdrop-blur-xl w-full lg:w-200 my-5 flex flex-col gap-5">
class="rounded-xl p-5 bg-white/50 backdrop-blur-xl w-full lg:w-200 my-5 flex flex-col gap-5" <div class="text-xl font-normal">{{ t('about.title') }}</div>
> <div class="flex flex-col gap-2 items-center">
<div class="text-xl font-normal">{{ t("about.title") }}</div> <NuxtImg src="/logo.png" class="size-20 rounded-xl" />
<div class="flex flex-col gap-2 items-center"> <div class="text-xl">{{ site_title ?? '015' }}</div>
<NuxtImg src="/logo.png" class="size-20 rounded-xl" /> <div class="text-sm opacity-75 text-center px-5">
<div class="text-xl">{{ site_title ?? "015" }}</div> {{ site_desc ?? t('seo.desc') }}
<div class="text-sm opacity-75 text-center px-5">
{{ site_desc ?? t("seo.desc") }}
</div>
</div>
<div class="font-semibold">{{ t("about.systemInfo") }}</div>
<template v-if="isLoading">
<div class="flex flex-row gap-2">
<Skeleton class="w-full h-20 rounded-xl" v-for="i in 2" :key="i" />
</div>
</template>
<template v-else>
<div class="grid grid-cols-2 gap-2">
<div class="rounded-xl bg-white/50 flex-1 flex flex-col p-3">
<div class="opacity-75 text-xs">{{ t("about.systemVersion") }}</div>
<div class="text-xl font-semibold">
{{ data?.version ?? "dev" }}
</div>
</div>
<div class="rounded-xl bg-white/50 flex-1 flex flex-col p-3">
<div class="opacity-75 text-xs">{{ t("about.storage") }}</div>
<div class="text-right flex flex-row items-baseline">
<span class="text-lg font-semibold">{{
filesize(currentFileSize ?? 0)
}}</span>
<span class="text-md opacity-75"
>/ {{ filesize(data?.max_limit?.file_size ?? 0) }}</span
>
</div>
<div class="rounded-full w-full h-1 bg-black/10">
<div
class="rounded-full h-full bg-blue-500"
:style="{
width: `${(currentFileSize / (data?.max_limit?.file_size ?? 0)) * 100}%`,
}"
></div>
</div>
</div>
</div>
</template>
<div class="font-semibold">{{ t("about.analysis") }}</div>
<template v-if="isLoading">
<div class="flex flex-row gap-2">
<Skeleton class="w-full h-96 rounded-xl" />
</div>
</template>
<template v-else>
<div class="flex flex-col gap-2 bg-white/50 w-full rounded-xl py-5">
<div class="flex flex-row gap-2 px-5">
<div
:class="
cx(
'rounded-md min-w-30 flex flex-col px-3 py-1.5 cursor-pointer',
currentChartTab === tab.value && 'bg-black/10',
)
"
v-for="tab in chartTabs"
:key="tab.value"
@click="
() => {
currentChartTab = tab.value as 'storage' | 'queue';
}
"
>
<div class="opacity-75 text-xs">{{ tab.label }}</div>
<div class="text-lg font-semibold">{{ tab.total }}</div>
</div>
</div>
<AreaChart
v-if="currentChartData"
class="h-64 w-full"
:key="currentChartTab"
:index="currentChartData.index"
:data="currentChartData.data"
:categories="currentChartData.categories"
:show-grid-line="false"
:show-legend="false"
:show-y-axis="true"
:show-x-axis="true"
:colors="currentChartData.colors"
:custom-tooltip="AboutChartTooltip"
:curve-type="CurveType.CatmullRom"
/>
</div>
</template>
<template v-if="isLoading">
<div class="flex flex-row gap-2">
<Skeleton class="w-full h-20 rounded-xl" v-for="i in 2" :key="i" />
</div>
</template>
<template v-else>
<div class="grid grid-cols-1 md:grid-cols-2 gap-2">
<div class="flex flex-col gap-3" v-for="user in users" :key="user.name">
<div class="font-semibold">{{ user.title }}</div>
<div
class="rounded-xl bg-white/50 hover:bg-white/40 flex-1 flex flex-row items-center gap-2 p-3 cursor-pointer"
@click="
() => {
handleUserClick(user);
}
"
>
<div class="size-10 rounded-full bg-white/50">
<NuxtImg
:src="genUserAvatar(user)"
class="size-full rounded-full"
/>
</div> </div>
<div class="text-md font-semibold">{{ user.name }}</div>
</div>
</div> </div>
</div> <div class="font-semibold">{{ t('about.systemInfo') }}</div>
</template> <template v-if="isLoading">
</div> <div class="flex flex-row gap-2">
<Skeleton class="w-full h-20 rounded-xl" v-for="i in 2" :key="i" />
</div>
</template>
<template v-else>
<div class="grid grid-cols-2 gap-2">
<div class="rounded-xl bg-white/50 flex-1 flex flex-col p-3">
<div class="opacity-75 text-xs">{{ t('about.systemVersion') }}</div>
<div class="text-xl font-semibold flex items-center gap-1">
{{ data?.version ?? 'dev' }}
<span class="text-xs px-2 py-0.5 rounded bg-primary/20 text-primary">{{ dayjs(data?.build_time * 1000).fromNow() }}</span>
</div>
</div>
<div class="rounded-xl bg-white/50 flex-1 flex flex-col p-3">
<div class="opacity-75 text-xs">{{ t('about.storage') }}</div>
<div class="text-right flex flex-row items-baseline">
<span class="text-lg font-semibold">{{ filesize(currentFileSize ?? 0) }}</span>
<span class="text-md opacity-75">/ {{ filesize(data?.max_limit?.file_size ?? 0) }}</span>
</div>
<Progress class="h-1" :model-value="(currentFileSize / (data?.max_limit?.file_size ?? 0)) * 100" />
</div>
</div>
</template>
<div class="font-semibold">{{ t('about.analysis') }}</div>
<template v-if="isLoading">
<div class="flex flex-row gap-2">
<Skeleton class="w-full h-96 rounded-xl" />
</div>
</template>
<template v-else>
<div class="flex flex-col gap-2 bg-white/50 w-full rounded-xl py-5">
<div class="flex flex-row gap-2 px-5">
<div
:class="cx('rounded-md min-w-30 flex flex-col px-3 py-1.5 cursor-pointer', currentChartTab === tab.value && 'bg-black/10')"
v-for="tab in chartTabs"
:key="tab.value"
@click="
() => {
currentChartTab = tab.value as 'storage' | 'queue'
}
"
>
<div class="opacity-75 text-xs">{{ tab.label }}</div>
<div class="text-lg font-semibold">{{ tab.total }}</div>
</div>
</div>
<AreaChart
v-if="currentChartData"
class="h-64 w-full"
:key="currentChartTab"
:index="currentChartData.index"
:data="currentChartData.data"
:categories="currentChartData.categories"
:show-grid-line="false"
:show-legend="false"
:show-y-axis="true"
:show-x-axis="true"
:colors="currentChartData.colors"
:custom-tooltip="AboutChartTooltip"
:curve-type="CurveType.CatmullRom"
/>
</div>
</template>
<template v-if="isLoading">
<div class="flex flex-row gap-2">
<Skeleton class="w-full h-20 rounded-xl" v-for="i in 2" :key="i" />
</div>
</template>
<template v-else>
<div class="grid grid-cols-1 md:grid-cols-2 gap-2">
<div class="flex flex-col gap-3" v-for="user in users" :key="user.name">
<div class="font-semibold">{{ user.title }}</div>
<div
class="rounded-xl bg-white/50 hover:bg-white/40 flex-1 flex flex-row items-center gap-2 p-3 cursor-pointer"
@click="
() => {
handleUserClick(user)
}
"
>
<div class="size-10 rounded-full bg-white/50">
<NuxtImg :src="genUserAvatar(user)" class="size-full rounded-full" />
</div>
<div class="text-md font-semibold">{{ user.name }}</div>
</div>
</div>
</div>
</template>
</div>
</template> </template>

View File

@@ -9,7 +9,6 @@
"dev:backend": "cd backend && air", "dev:backend": "cd backend && air",
"dev:worker": "cd worker && air", "dev:worker": "cd worker && air",
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"postinstall": "npx husky init",
"prepare": "husky" "prepare": "husky"
}, },
"workspaces": [ "workspaces": [

4457
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff