Skip to content

Commit 013eb7c

Browse files
committed
尺寸提取功能优化
1 parent a03766a commit 013eb7c

21 files changed

+13
-20
lines changed

css/23.e63939dd.css.gz

-12.5 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

css/280.6f363073.css.gz

12.5 KB
Binary file not shown.

functions/api/huggingface/commitUpload.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export async function onRequestPost(context) {
9090
Channel: "HuggingFace",
9191
ChannelName: hfChannel.name || "HuggingFace_env",
9292
FileSize: (fileSize / 1024 / 1024).toFixed(2),
93+
FileSizeBytes: fileSize,
9394
HfRepo: hfChannel.repo,
9495
HfFilePath: filePath,
9596
HfToken: hfChannel.token,

functions/upload/index.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,8 @@ async function processFileUpload(context, formdata = null) {
139139
let imageDimensions = null;
140140
if (fileType.startsWith('image/')) {
141141
try {
142-
// JPEG 需要更多数据(EXIF 可能很大),其他格式 512 字节足够
143-
const lowerType = fileType.toLowerCase();
144-
const isJpeg = lowerType === 'image/jpeg' || lowerType === 'image/jpg' || lowerType === 'image/pjpeg';
145-
const readSize = isJpeg ? 65536 : 512;
146-
const headerBuffer = await file.slice(0, readSize).arrayBuffer();
142+
// 统一读取 64KB,足以覆盖 JPEG 的 EXIF 数据和其他格式
143+
const headerBuffer = await file.slice(0, 65536).arrayBuffer();
147144
imageDimensions = getImageDimensions(headerBuffer, fileType);
148145
} catch (error) {
149146
console.error('Error reading image dimensions:', error);
@@ -287,16 +284,12 @@ async function uploadFileToCloudflareR2(context, fullId, metadata, returnLink) {
287284

288285
const R2DataBase = env.img_r2;
289286

290-
// 写入R2数据库,获取实际存储大小
291-
const r2Object = await R2DataBase.put(fullId, formdata.get('file'));
287+
// 写入R2数据库
288+
await R2DataBase.put(fullId, formdata.get('file'));
292289

293290
// 更新metadata
294291
metadata.Channel = "CloudflareR2";
295292
metadata.ChannelName = r2Channel.name || "R2_env";
296-
// 使用 R2 返回的实际文件大小
297-
if (r2Object && r2Object.size) {
298-
metadata.FileSize = (r2Object.size / 1024 / 1024).toFixed(2);
299-
}
300293

301294
// 图像审查,采用R2的publicUrl
302295
const R2PublicUrl = r2Channel.publicUrl;
@@ -782,7 +775,6 @@ async function uploadFileToHuggingFace(context, fullId, metadata, returnLink) {
782775
// 更新 metadata
783776
metadata.Channel = "HuggingFace";
784777
metadata.ChannelName = hfChannel.name || "HuggingFace_env";
785-
metadata.FileSize = (file.size / 1024 / 1024).toFixed(2);
786778
metadata.HfRepo = hfChannel.repo;
787779
metadata.HfFilePath = hfFilePath;
788780
metadata.HfToken = hfChannel.token;

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/logo.png"><link rel="apple-touch-icon" href="/logo.png"><link rel="mask-icon" href="/logo.png" color="#f4b400"><meta name="description" content="Sanyue ImgHub - A modern file hosting platform"><meta name="keywords" content="Sanyue, ImgHub, file hosting, image hosting, cloud storage"><meta name="author" content="SanyueQi"><title>Sanyue ImgHub</title><script defer="defer" src="/js/chunk-vendors.92518219.js"></script><script defer="defer" src="/js/app.1611e1ad.js"></script><link href="/css/chunk-vendors.4363ed49.css" rel="stylesheet"><link href="/css/app.3e1508bd.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but sanyue_imghub doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>
1+
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/logo.png"><link rel="apple-touch-icon" href="/logo.png"><link rel="mask-icon" href="/logo.png" color="#f4b400"><meta name="description" content="Sanyue ImgHub - A modern file hosting platform"><meta name="keywords" content="Sanyue, ImgHub, file hosting, image hosting, cloud storage"><meta name="author" content="SanyueQi"><title>Sanyue ImgHub</title><script defer="defer" src="/js/chunk-vendors.92518219.js"></script><script defer="defer" src="/js/app.28705dac.js"></script><link href="/css/chunk-vendors.4363ed49.css" rel="stylesheet"><link href="/css/app.3e1508bd.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but sanyue_imghub doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>

index.html.gz

0 Bytes
Binary file not shown.

js/23.180d02c4.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

js/23.180d02c4.js.gz

-21.2 KB
Binary file not shown.

js/23.180d02c4.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)