feat: 기능 추가 과정중

This commit is contained in:
donghyeon-ka
2026-07-30 15:58:20 +09:00
parent d3ef801fe6
commit 6c52cdb916
648 changed files with 126325 additions and 6680 deletions
+46 -10
View File
@@ -20,7 +20,7 @@ import type {
ServiceWorkerUpdatePort,
VersionedOfflineRepository,
WorkerTaskPort,
} from "./contracts.js";
} from "./contracts.ts";
export function success<T>(value: T): CapabilityResult<T> {
return Object.freeze({ ok: true, value });
@@ -221,11 +221,35 @@ export class FakeFileTransferAdapter implements FileTransferPort {
) {
return failure("LIMIT_EXCEEDED", false, "File size or type is not allowed.");
}
input.onProgress({
transferredBytes: input.file.size,
totalBytes: input.file.size,
});
return success({ resourceId: `fake:${input.file.name}` });
let transferredBytes = 0;
for await (const chunk of input.file.content.chunks) {
const duringTransfer = aborted(input.signal);
if (duringTransfer) return duringTransfer;
transferredBytes += chunk.byteLength;
if (transferredBytes > input.file.size) {
return failure(
"INTEGRITY_FAILED",
false,
"Uploaded bytes exceeded the declared file size.",
);
}
input.onProgress({
phase: "TRANSFERRING",
transferredBytes,
totalBytes: input.file.size,
});
}
if (
transferredBytes !== input.file.size ||
input.file.content.byteLength !== input.file.size
) {
return failure(
"INTEGRITY_FAILED",
false,
"Uploaded bytes did not match the declared file size.",
);
}
return success({ resourceId: "fake:opaque-resource" });
}
async download(input: Parameters<FileTransferPort["download"]>[0]) {
@@ -235,11 +259,23 @@ export class FakeFileTransferAdapter implements FileTransferPort {
return failure("EXPIRED_RESOURCE", true, "The download link expired.");
}
const bytes = new TextEncoder().encode(input.resourceId);
input.onProgress({
transferredBytes: bytes.byteLength,
totalBytes: bytes.byteLength,
const chunks = async function* () {
if (input.signal.aborted) return;
input.onProgress({
phase: "TRANSFERRING" as const,
transferredBytes: bytes.byteLength,
totalBytes: bytes.byteLength,
});
yield bytes.slice();
};
return success({
fileName: "download.bin",
mediaType: "application/octet-stream",
content: {
byteLength: bytes.byteLength,
chunks: chunks(),
},
});
return success(bytes);
}
}