File size: 868 Bytes
e4e0e54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import path from "node:path"

import { completedMetadataDirFilePath, pendingMetadataDirFilePath } from "../config.mts"
import { readVideoMetadataFile } from "./readVideoMetadataFile.mts"

export const getVideo = async (ownerId: string, videoId: string) => {
  const videoFileName = `${ownerId}_${videoId}.json`

  const completedVideoMetadataFilePath = path.join(completedMetadataDirFilePath, videoFileName)
  const pendingVideoMetadataFilePath = path.join(pendingMetadataDirFilePath, videoFileName)

  try {
    const completedVideo = await readVideoMetadataFile(completedVideoMetadataFilePath)
    return completedVideo
  } catch (err) {
    try {
      const pendingVideo= await readVideoMetadataFile(pendingVideoMetadataFilePath)
      return pendingVideo
    } catch (err) {
      throw new Error(`couldn't find video ${videoId} for owner ${ownerId}`)
    }
  }
}