Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- .build_counter +1 -1
- Dockerfile +2 -2
- worker/colorRmAssets.ts +2 -42
.build_counter
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
12
|
Dockerfile
CHANGED
|
@@ -25,6 +25,6 @@ ENV NODE_ENV=development
|
|
| 25 |
EXPOSE 7860
|
| 26 |
|
| 27 |
# Run disk check, init, restore, then start dev server, backup worker, and PDF convert server concurrently
|
| 28 |
-
|
| 29 |
|
| 30 |
-
CMD ["sh", "-c", "df -h && npx concurrently \"npm run dev\" "]
|
|
|
|
| 25 |
EXPOSE 7860
|
| 26 |
|
| 27 |
# Run disk check, init, restore, then start dev server, backup worker, and PDF convert server concurrently
|
| 28 |
+
CMD ["sh", "-c", "df -h && node cmd/hf_init.mjs && node cmd/hf_restore.mjs && npx concurrently \"npm run dev\" \"node cmd/hf_backup.mjs\" \"node cmd/pdf_convert_server.mjs\""]
|
| 29 |
|
| 30 |
+
#CMD ["sh", "-c", "df -h && npx concurrently \"npm run dev\" "]
|
worker/colorRmAssets.ts
CHANGED
|
@@ -106,28 +106,8 @@ export async function handleColorRmDownload(request: IRequest, env: Env) {
|
|
| 106 |
|
| 107 |
console.log(`[handleColorRmDownload] Base file FOUND, size: ${obj.size} bytes`);
|
| 108 |
|
| 109 |
-
//
|
| 110 |
const buffer = await obj.arrayBuffer();
|
| 111 |
-
const uint8Array = new Uint8Array(buffer.slice(0, 100)); // Check first 100 bytes
|
| 112 |
-
const textSample = new TextDecoder().decode(uint8Array);
|
| 113 |
-
|
| 114 |
-
// Check if it looks like base64 content (contains only base64 chars and padding)
|
| 115 |
-
// But exclude common binary file headers like PDF (%PDF-), JPEG (每脴每), PNG (鈥癙NG), etc.
|
| 116 |
-
if (textSample.startsWith('%PDF-') ||
|
| 117 |
-
(textSample.charCodeAt(0) === 0xFF && textSample.charCodeAt(1) === 0xD8) || // JPEG
|
| 118 |
-
textSample.startsWith('\x89PNG') || // PNG
|
| 119 |
-
textSample.startsWith('<svg')) { // SVG
|
| 120 |
-
// Recognized binary file header, not base64
|
| 121 |
-
console.log(`[handleColorRmDownload] File appears to be proper binary data (recognized header). Sample: ${textSample.substring(0, 50)}...`);
|
| 122 |
-
} else {
|
| 123 |
-
// Check if it looks like base64 content (contains only base64 chars and padding)
|
| 124 |
-
const base64Pattern = /^[A-Za-z0-9+/]{10,}/; // At least 10 chars to be considered base64
|
| 125 |
-
if (base64Pattern.test(textSample.replace(/\s/g, ''))) {
|
| 126 |
-
console.log(`[handleColorRmDownload] WARNING: File appears to be base64 encoded instead of binary! Sample: ${textSample.substring(0, 50)}...`);
|
| 127 |
-
} else {
|
| 128 |
-
console.log(`[handleColorRmDownload] File appears to be proper binary data. Sample: ${textSample.substring(0, 50)}...`);
|
| 129 |
-
}
|
| 130 |
-
}
|
| 131 |
|
| 132 |
const headers = new Headers()
|
| 133 |
obj.writeHttpMetadata(headers)
|
|
@@ -272,28 +252,8 @@ export async function handleColorRmPageDownload(request: IRequest, env: Env) {
|
|
| 272 |
|
| 273 |
console.log(`[PageDownload] Page file FOUND for ${pageId}, size: ${obj.size} bytes`);
|
| 274 |
|
| 275 |
-
//
|
| 276 |
const buffer = await obj.arrayBuffer();
|
| 277 |
-
const uint8Array = new Uint8Array(buffer.slice(0, 100)); // Check first 100 bytes
|
| 278 |
-
const textSample = new TextDecoder().decode(uint8Array);
|
| 279 |
-
|
| 280 |
-
// Check if it looks like base64 content (contains only base64 chars and padding)
|
| 281 |
-
// But exclude common binary file headers like PDF (%PDF-), JPEG (每脴每), PNG (鈥癙NG), etc.
|
| 282 |
-
if (textSample.startsWith('%PDF-') ||
|
| 283 |
-
(textSample.charCodeAt(0) === 0xFF && textSample.charCodeAt(1) === 0xD8) || // JPEG
|
| 284 |
-
textSample.startsWith('\x89PNG') || // PNG
|
| 285 |
-
textSample.startsWith('<svg')) { // SVG
|
| 286 |
-
// Recognized binary file header, not base64
|
| 287 |
-
console.log(`[PageDownload] Page ${pageId} appears to be proper binary data (recognized header). Sample: ${textSample.substring(0, 50)}...`);
|
| 288 |
-
} else {
|
| 289 |
-
// Check if it looks like base64 content (contains only base64 chars and padding)
|
| 290 |
-
const base64Pattern = /^[A-Za-z0-9+/]{10,}/; // At least 10 chars to be considered base64
|
| 291 |
-
if (base64Pattern.test(textSample.replace(/\s/g, ''))) {
|
| 292 |
-
console.log(`[PageDownload] WARNING: Page ${pageId} appears to be base64 encoded instead of binary! Sample: ${textSample.substring(0, 50)}...`);
|
| 293 |
-
} else {
|
| 294 |
-
console.log(`[PageDownload] Page ${pageId} appears to be proper binary data. Sample: ${textSample.substring(0, 50)}...`);
|
| 295 |
-
}
|
| 296 |
-
}
|
| 297 |
|
| 298 |
const headers = new Headers()
|
| 299 |
obj.writeHttpMetadata(headers)
|
|
|
|
| 106 |
|
| 107 |
console.log(`[handleColorRmDownload] Base file FOUND, size: ${obj.size} bytes`);
|
| 108 |
|
| 109 |
+
// Read the buffer for response
|
| 110 |
const buffer = await obj.arrayBuffer();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
const headers = new Headers()
|
| 113 |
obj.writeHttpMetadata(headers)
|
|
|
|
| 252 |
|
| 253 |
console.log(`[PageDownload] Page file FOUND for ${pageId}, size: ${obj.size} bytes`);
|
| 254 |
|
| 255 |
+
// Read the buffer for response
|
| 256 |
const buffer = await obj.arrayBuffer();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
|
| 258 |
const headers = new Headers()
|
| 259 |
obj.writeHttpMetadata(headers)
|