File size: 1,689 Bytes
43dd1ac
 
8f24b44
43dd1ac
8f24b44
43dd1ac
 
 
 
 
8f24b44
 
 
43dd1ac
 
 
 
 
8f24b44
 
43dd1ac
 
 
 
8f24b44
 
43dd1ac
 
 
 
8f24b44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43dd1ac
8f24b44
43dd1ac
 
 
8f24b44
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"use server"

import { Video, VideoAPIRequest, GenericAPIResponse, VideoStatusRequest, VideoStatus } from "@/app/types"

import { GET, POST, DELETE, PATCH } from "./base"

// note: for security purposes we do not directly expose the VideoChain API:
// all calls are protected with a token, that way it the VideooChain API can stay
// lightweight, security and quotas are handled outside

// this should be used by the admin only
export const getAllVideos = async () => {
  const tasks = await GET<Video[]>("", [])

  return tasks
}

// return all tasks of a owner
export const getVideos = async (ownerId: string) => {
  const tasks = await GET<Video[]>(ownerId, [])

  return tasks
}

export const getVideo = async (ownerId: string, videoId: string) => {
  const task = await GET<Video>(`${ownerId}/${videoId}`, null as unknown as Video)

  return task
}

export const setVideoStatus = async (ownerId: string, videoId: string, status: VideoStatus) => {
  const task = await PATCH<VideoStatusRequest, GenericAPIResponse>(`${ownerId}/${videoId}`, { status }, null as unknown as Video)

  return task
}

export const deleteVideo = async (ownerId: string, videoId: string) => {
  const task = await DELETE<GenericAPIResponse>(`${ownerId}/${videoId}`, { success: true })

  return task
}

/*
export async function deleteVideos(ownerId: string, videoIds: string[]) {
  const task = await DELETE<GenericAPIResponse>(ownerAndVideoId, { success: true })
  
  return task
}
*/

export const createNewVideo = async (ownerId: string, taskRequest: VideoAPIRequest) => {
  const task = await POST<VideoAPIRequest, Video>(
    ownerId,
    taskRequest,
    null as unknown as Video
  )

  return task
}