fix: normalize web object sizes

This commit is contained in:
asepharyana
2026-07-07 06:27:18 +07:00
parent 1ef73fefa9
commit fbfff3d9ec
5 changed files with 46 additions and 11 deletions
+9 -6
View File
@@ -31,20 +31,21 @@ const mapDbRowToS3Record = (row: Record<string, unknown>): S3FileRecord => {
publicId: row.public_id as string,
telegramFileId: row.telegram_file_id as string,
telegramFileUniqueId: row.telegram_file_unique_id as string,
storageChatId: row.storage_chat_id as number,
storageMessageId: row.storage_message_id as number,
storageChatId: toNumber(row.storage_chat_id),
storageMessageId: toNumber(row.storage_message_id),
fileName: row.file_name as string,
mimeType: row.mime_type as string,
sizeBytes: row.size_bytes as number,
sizeBytes: toNumber(row.size_bytes),
fileType: row.file_type as string,
uploaderId: row.uploader_id as number,
uploaderId: toNumber(row.uploader_id),
fileHash: row.file_hash as string | null,
archiveTelegramFileId: row.archive_telegram_file_id as string | null,
archiveStorageMessageId: row.archive_storage_message_id as number | null,
archiveStorageMessageId:
row.archive_storage_message_id === null ? null : toNumber(row.archive_storage_message_id),
archiveFileName: row.archive_file_name as string | null,
archiveEntryName: row.archive_entry_name as string | null,
archiveMimeType: row.archive_mime_type as string | null,
archiveSizeBytes: row.archive_size_bytes as number | null,
archiveSizeBytes: row.archive_size_bytes === null ? null : toNumber(row.archive_size_bytes),
bucketId: row.bucket_id as string,
s3Key: row.s3_key as string,
storageBackend: (row.storage_backend as string) || 'telegram',
@@ -57,6 +58,8 @@ const mapDbRowToS3Record = (row: Record<string, unknown>): S3FileRecord => {
const escapeLike = (s: string): string => s.replace(/[%_\\]/g, '\\$&');
const toNumber = (value: unknown): number => Number(value ?? 0);
export const listObjectsByPrefix = async (
bucketId: string,
prefix: string,
+2 -1
View File
@@ -90,7 +90,8 @@ export const config: AppConfig = {
s3DefaultRegion: process.env.S3_DEFAULT_REGION || 'us-east-1',
proxyS3Get: process.env.PROXY_S3_GET !== 'false',
s3VhostDomains: parseDomains(
process.env.S3_VHOST_DOMAINS || 'upload.asepharyana.my.id,asepharyana.web.id,upload.asepharyana.web.id',
process.env.S3_VHOST_DOMAINS ||
'upload.asepharyana.my.id,asepharyana.web.id,upload.asepharyana.web.id',
),
};
+1 -1
View File
@@ -202,7 +202,7 @@
}
container.innerHTML = html;
};
const formatSize = (bytes) => { if (!bytes) return '0 B'; const u = ['B','KB','MB','GB','TB']; let i=0,s=bytes; while(s>=1024&&i<u.length-1){s/=1024;i++} return `${s.toFixed(i>0?1:0)} ${u[i]}`; };
const formatSize = (bytes) => { const size = Number(bytes); if (!Number.isFinite(size) || size <= 0) return '0 B'; const u = ['B','KB','MB','GB','TB']; let i=0,s=size; while(s>=1024&&i<u.length-1){s/=1024;i++} return `${s.toFixed(i>0?1:0)} ${u[i]}`; };
const formatDate = (iso) => { if(!iso)return ''; return new Date(iso).toLocaleDateString(undefined,{month:'short',day:'numeric',year:'numeric'}); };
const escapeHtml = (s) => { const d=document.createElement('div');d.textContent=s;return d.innerHTML; };
const debouncedSearch = () => { clearTimeout(searchTimer); searchTimer = setTimeout(loadObjects, 300); };
+1 -1
View File
@@ -83,7 +83,7 @@ export const handleListObjectsV1 = async (req: Request, params: RouteParams): Pr
key: o.s3Key,
fileName: o.fileName,
mimeType: o.mimeType,
sizeBytes: o.sizeBytes,
sizeBytes: Number(o.sizeBytes),
fileType: o.fileType,
etag: o.fileHash,
lastModified: