Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 62 additions & 36 deletions apps/server/public/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -806,17 +806,12 @@
"type": "null"
}
]
},
"downloadUrl": {
"type": "string",
"minLength": 1
}
},
"required": [
"fileName",
"contentType",
"size",
"downloadUrl"
"size"
]
},
{
Expand Down Expand Up @@ -1173,17 +1168,12 @@
"type": "null"
}
]
},
"downloadUrl": {
"type": "string",
"minLength": 1
}
},
"required": [
"fileName",
"contentType",
"size",
"downloadUrl"
"size"
]
},
{
Expand Down Expand Up @@ -7320,6 +7310,9 @@
"post": {
"operationId": "jobs.list",
"summary": "list",
"tags": [
"Jobs"
],
"requestBody": {
"required": true,
"content": {
Expand Down Expand Up @@ -7544,17 +7537,12 @@
"type": "null"
}
]
},
"downloadUrl": {
"type": "string",
"minLength": 1
}
},
"required": [
"fileName",
"contentType",
"size",
"downloadUrl"
"size"
]
},
{
Expand Down Expand Up @@ -7604,6 +7592,9 @@
"post": {
"operationId": "jobs.get",
"summary": "get",
"tags": [
"Jobs"
],
"requestBody": {
"required": true,
"content": {
Expand Down Expand Up @@ -7808,17 +7799,12 @@
"type": "null"
}
]
},
"downloadUrl": {
"type": "string",
"minLength": 1
}
},
"required": [
"fileName",
"contentType",
"size",
"downloadUrl"
"size"
]
},
{
Expand Down Expand Up @@ -7852,10 +7838,54 @@
}
}
},
"/jobs/downloadArtifact": {
"post": {
"operationId": "jobs.downloadArtifact",
"summary": "downloadArtifact",
"tags": [
"Jobs"
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"id": {
"type": "string",
"format": "uuid"
}
},
"required": [
"id"
]
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {
"application/octet-stream": {
"schema": {
"type": "string",
"format": "binary"
}
}
}
}
}
}
},
"/jobs/retry": {
"post": {
"operationId": "jobs.retry",
"summary": "retry",
"tags": [
"Jobs"
],
"requestBody": {
"required": true,
"content": {
Expand Down Expand Up @@ -8060,17 +8090,12 @@
"type": "null"
}
]
},
"downloadUrl": {
"type": "string",
"minLength": 1
}
},
"required": [
"fileName",
"contentType",
"size",
"downloadUrl"
"size"
]
},
{
Expand Down Expand Up @@ -8108,6 +8133,9 @@
"post": {
"operationId": "jobs.cancel",
"summary": "cancel",
"tags": [
"Jobs"
],
"requestBody": {
"required": true,
"content": {
Expand Down Expand Up @@ -8312,17 +8340,12 @@
"type": "null"
}
]
},
"downloadUrl": {
"type": "string",
"minLength": 1
}
},
"required": [
"fileName",
"contentType",
"size",
"downloadUrl"
"size"
]
},
{
Expand Down Expand Up @@ -8360,6 +8383,9 @@
"post": {
"operationId": "jobs.events",
"summary": "events",
"tags": [
"Jobs"
],
"responses": {
"200": {
"description": "OK",
Expand Down
12 changes: 12 additions & 0 deletions apps/server/scripts/generate-swagger-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const routerTagMap: Record<string, string> = {
downloads: "Downloads",
directories: "Directories",
ai: "AI",
jobs: "Jobs",
utils: "Utilities",
};

Expand Down Expand Up @@ -97,6 +98,17 @@ async function generateOpenAPISpec() {
// デフォルトの概要(operationIdを綺麗にする)
operation.summary = opId.split(".").pop() || opId;
}

if (opId === "jobs.downloadArtifact" && operation.responses?.[200]) {
operation.responses[200] = {
description: "OK",
content: {
"application/octet-stream": {
schema: { type: "string", format: "binary" },
},
},
};
}
}
}
}
Expand Down
61 changes: 0 additions & 61 deletions apps/server/src/infrastructure/api-clients/shared/endpoints.ts

This file was deleted.

49 changes: 9 additions & 40 deletions apps/server/src/infrastructure/api-clients/sources-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
* Media Sources API Client
* Handles all API calls related to media sources
*
* NOTE: Most operations use oRPC, but dump/import still use dedicated HTTP routes.
* Source operations use oRPC, including binary export artifacts.
*/

import { downloadCompletedJobArtifact } from "@solid-imager/client";
import type { mediaSourceInfoSchema } from "@solid-imager/core/domain/sources/schemas";
import type { z } from "zod";
import { orpc } from "~/infrastructure/api-clients/orpc-client";
Expand Down Expand Up @@ -96,17 +97,12 @@ export async function fetchSourceDump(
opts?: { includeImages?: boolean },
): Promise<Blob> {
const includeImages = opts?.includeImages ?? false;
const url = `/api/sources/${id}/dump?mode=${mode}&includeImages=${includeImages}`;
const response = await fetch(url, {
method: "GET",
const job = await orpc.sources.enqueueExport({
id,
mode,
includeImages,
});

if (!response.ok) {
const errorText = await response.text();
throw new Error(`Failed to download dump: ${response.status} ${errorText}`);
}

return response.blob();
return downloadCompletedJobArtifact(orpc.jobs, job.id);
}

export function restoreSource(id: string, data: unknown) {
Expand All @@ -123,21 +119,7 @@ export function restoreSource(id: string, data: unknown) {
* @returns Import result
*/
export async function importSourceZip(id: string, file: File) {
const url = `/api/sources/${id}/import`;
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/zip",
},
body: file,
});

if (!response.ok) {
const errorText = await response.text();
throw new Error(`Failed to import ZIP: ${response.status} ${errorText}`);
}

return await response.json();
return orpc.sources.importZip({ id, file });
}

export async function importSourceNdjson(id: string, file: File) {
Expand All @@ -148,18 +130,5 @@ export async function importSourceNdjson(id: string, file: File) {
}

export async function importSourceLanceDB(id: string, file: File) {
const url = `/api/sources/${id}/import-lancedb`;
const response = await fetch(url, {
method: "POST",
body: file,
});

if (!response.ok) {
const errorText = await response.text();
throw new Error(
`Failed to import LanceDB: ${response.status} ${errorText}`,
);
}

return await response.json();
return orpc.sources.importLanceDB({ id, file });
}
Loading