@aj-archipelago/cortex
Version:
Cortex is a GraphQL API for AI. It provides a simple, extensible interface for using AI services from OpenAI, Azure and others.
58 lines (47 loc) • 1.6 kB
JavaScript
import { ConversionService } from "./ConversionService.js";
import { getFileStoreMap, setFileStoreMap } from "../redis.js";
import { urlExists } from "../helper.js";
import { gcsUrlExists, uploadChunkToGCS, gcs } from "../blobHandler.js";
import { downloadFile } from "../fileChunker.js";
import { saveFileToBlob } from "../blobHandler.js";
import { moveFileToPublicFolder } from "../localFileHandler.js";
import { v4 as uuidv4 } from "uuid";
export class FileConversionService extends ConversionService {
constructor(context, useAzure = true) {
super(context);
this.useAzure = useAzure;
}
async _getFileStoreMap(key) {
return getFileStoreMap(key);
}
async _setFileStoreMap(key, value) {
return setFileStoreMap(key, value);
}
async _urlExists(url) {
return urlExists(url);
}
async _gcsUrlExists(url) {
return gcsUrlExists(url);
}
async _downloadFile(url, destination) {
return downloadFile(url, destination);
}
async _saveConvertedFile(filePath, requestId, filename = null) {
// Generate a fallback requestId if none supplied (e.g. during checkHash calls)
const reqId = requestId || uuidv4();
let fileUrl;
if (this.useAzure) {
const savedBlob = await saveFileToBlob(filePath, reqId, filename);
fileUrl = savedBlob.url;
} else {
fileUrl = await moveFileToPublicFolder(filePath, reqId);
}
return { url: fileUrl };
}
async _uploadChunkToGCS(filePath, requestId, filename = null) {
return uploadChunkToGCS(filePath, requestId, filename);
}
_isGCSConfigured() {
return !!gcs;
}
}