Skip to content

Commit acb0820

Browse files
committed
set upload original path
1 parent 009324c commit acb0820

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@inspatial/cloud",
3-
"version": "0.6.14",
3+
"version": "0.6.15",
44
"license": "Apache-2.0",
55
"exports": {
66
".": "./mod.ts",

src/files/actions/upload-file.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,13 @@ export const uploadFile = new CloudAPIAction("upload", {
7777
accountFolder = joinPath(inCloud.publicFilesPath, accountId);
7878
path = joinPath(accountFolder, newFileName);
7979
}
80-
await Deno.mkdir(accountFolder, {
80+
const originalFolder = joinPath(accountFolder, "original");
81+
await Deno.mkdir(originalFolder, {
8182
recursive: true,
8283
});
8384
cloudFile.filePath = path;
8485
if (optimizeImage) {
86+
path = joinPath(originalFolder, newFileName);
8587
const defaultSize = 1000;
8688
cloudFile.optimizeImage = true;
8789
cloudFile.optimizeWidth = optimizeWidth || defaultSize;

src/files/image-ops/resize-worker.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference lib="webworker" />
22

3+
import { joinPath } from "../../utils/path-utils.ts";
34
import type {
45
ErrorResult,
56
ImageMessageEvent,
@@ -68,9 +69,12 @@ const commandHandlers: {
6869
},
6970
async optimize(msg) {
7071
const { filePath, width, height, format } = msg;
71-
const fileData = await Deno.readFile(filePath);
7272
let resized: Uint8Array | null = null;
73-
73+
const pathParts = filePath.split("/");
74+
const fileName = pathParts.pop()!;
75+
const originalsDir = joinPath(...pathParts, "original");
76+
const originalPath = joinPath(originalsDir, fileName);
77+
const fileData = await Deno.readFile(originalPath);
7478
switch (format) {
7579
case "jpeg":
7680
resized = resizeImage.toJpg(fileData, width, height);
@@ -101,19 +105,18 @@ const commandHandlers: {
101105
}
102106
const outputFilePath = filePath.replace(
103107
/\.[^.]+$/,
104-
`-resized.${format === "jpeg" ? "jpg" : "png"}`,
108+
`.${format === "jpeg" ? "jpg" : "png"}`,
105109
);
106-
const newFilePath = outputFilePath.replace(/-resized\./, ".");
110+
107111
await Deno.writeFile(outputFilePath, resized);
108-
await Deno.remove(filePath);
109-
await Deno.rename(outputFilePath, newFilePath);
112+
await Deno.remove(originalPath);
110113

111114
return {
112115
command: "optimize",
113116
id: msg.id,
114117
success: true,
115118
fileSize: resized.byteLength,
116-
newFilePath,
119+
newFilePath: outputFilePath,
117120
thumbnailPath: thumbnail ? thumbPath : "",
118121
thumbnailSize: thumbnail ? thumbnail.byteLength : 0,
119122
};

src/in-queue/in-queue.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import type {
99
OptimizeImageTaskData,
1010
QueueCommand,
1111
QueueMessage,
12-
QueueThumb,
1312
TaskInfo,
1413
} from "./types.ts";
1514
import type { InSpatialORM } from "../orm/inspatial-orm.ts";
@@ -18,11 +17,10 @@ import { createInLog } from "#inLog";
1817
import type { InTaskGlobal } from "./entry-types/in-task/_in-task-global.type.ts";
1918
import type { GenericEntry } from "../orm/entry/entry-base.ts";
2019
import { ImageOps } from "../files/image-ops/image-ops.ts";
21-
import { CloudFile } from "../files/entries/_cloud-file.type.ts";
22-
import { GlobalCloudFile } from "../files/entries/_global-cloud-file.type.ts";
20+
import type { CloudFile } from "../files/entries/_cloud-file.type.ts";
21+
import type { GlobalCloudFile } from "../files/entries/_global-cloud-file.type.ts";
2322
import MimeTypes from "../files/mime-types/mime-types.ts";
24-
import { InTask } from "./entry-types/in-task/_in-task.type.ts";
25-
import { ListOptions } from "@inspatial/cloud-client/types";
23+
import type { InTask } from "./entry-types/in-task/_in-task.type.ts";
2624

2725
export class InQueue extends InCloud {
2826
clients: Map<string, WebSocket> = new Map();
@@ -196,6 +194,7 @@ export class InQueue extends InCloud {
196194
this.broadcastEnd("completed", startTime, message);
197195
return;
198196
}
197+
199198
this.broadcastEnd("failed", startTime, message);
200199
}
201200

@@ -243,7 +242,9 @@ export class InQueue extends InCloud {
243242
this.broadcastEnd("completed", startTime, message);
244243
return;
245244
}
246-
245+
this.inLog.error(result, {
246+
subject: "Image optimization failed",
247+
});
247248
this.broadcastEnd("failed", startTime, message);
248249
}
249250
async runInTask(taskInfo: TaskInfo) {

0 commit comments

Comments
 (0)