Skip to content

Commit

Permalink
Add some log and errors to test createAsset
Browse files Browse the repository at this point in the history
  • Loading branch information
JuseGit committed Aug 6, 2024
1 parent acd8322 commit 1feab11
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
25 changes: 8 additions & 17 deletions src/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ import { deepMerge, camelCase, isRemote, toSafePath } from './utils/utils.js';
import * as transformers from './providers/transformers.js';

export interface Asset {
status:
| 'sourced'
| 'pending'
| 'uploading'
| 'processing'
| 'ready'
| 'error';
status: 'sourced' | 'pending' | 'uploading' | 'processing' | 'ready' | 'error';
originalFilePath: string;
// TODO: should we add a `filePath` field which would store the file path
// without the configurable folder? This would allow us to change the folder
Expand Down Expand Up @@ -59,8 +53,7 @@ export async function getAssetConfigPath(filePath: string) {
async function getAssetPath(filePath: string) {
if (!isRemote(filePath)) return filePath;

const { folder, remoteSourceAssetPath = defaultRemoteSourceAssetPath } =
await getVideoConfig();
const { folder, remoteSourceAssetPath = defaultRemoteSourceAssetPath } = await getVideoConfig();

if (!folder) throw new Error('Missing video `folder` config.');

Expand All @@ -76,10 +69,7 @@ function defaultRemoteSourceAssetPath(url: string) {
return toSafePath(decodeURIComponent(`${urlObj.hostname}${urlObj.pathname}`));
}

export async function createAsset(
filePath: string,
assetDetails?: Partial<Asset>
) {
export async function createAsset(filePath: string, assetDetails?: Partial<Asset>) {
const videoConfig = await getVideoConfig();
const assetConfigPath = await getAssetConfigPath(filePath);

Expand All @@ -106,15 +96,16 @@ export async function createAsset(
}
}

throw new Error(
`CREATEASSET filePath:${filePath} assetDetails:${assetDetails} videoConfig:${videoConfig} assetConfigPath:${assetConfigPath}`
);

videoConfig.saveAsset(assetConfigPath, newAssetDetails);

return newAssetDetails;
}

export async function updateAsset(
filePath: string,
assetDetails: Partial<Asset>
) {
export async function updateAsset(filePath: string, assetDetails: Partial<Asset>) {
const assetConfigPath = await getAssetConfigPath(filePath);
const currentAsset = await getAsset(filePath);
const { saveAsset } = await getVideoConfig();
Expand Down
8 changes: 5 additions & 3 deletions src/request-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { isRemote } from './utils/utils.js';

// App Router
export async function GET(request: Request) {
const { searchParams } = new URL(request.url)
const { searchParams } = new URL(request.url);
const url = searchParams.get('url');
const { status, data } = await handleRequest(url);
// @ts-ignore - Response.json() is only valid from TypeScript 5.2
Expand All @@ -23,23 +23,25 @@ async function handleRequest(url?: string | null) {
if (!url) {
return {
status: 400,
data: { error: 'url parameter is required' }
data: { error: 'url parameter is required' },
};
}

if (!isRemote(url)) {
// todo: handle local files via string src
return {
status: 400,
data: { error: 'local files should be imported as a module' }
data: { error: 'local files should be imported as a module' },
};
}

let asset;
try {
console.log('handleRequest: GETASSET ', url);
asset = await getAsset(url);
} catch {
// todo: does this require auth?
console.log('handleRequest: CREATEASSET ', url);
asset = await createAsset(url);

if (asset) {
Expand Down

0 comments on commit 1feab11

Please sign in to comment.