File size: 1,954 Bytes
43dd1ac
 
73cc2a0
 
8f24b44
43dd1ac
8f24b44
43dd1ac
4fe04e4
43dd1ac
 
 
 
8f24b44
 
 
43dd1ac
 
 
 
 
8f24b44
 
43dd1ac
 
 
 
8f24b44
 
43dd1ac
 
 
 
8f24b44
 
 
73cc2a0
 
8f24b44
 
 
e411e71
8f24b44
e411e71
8f24b44
 
 
e411e71
8f24b44
 
 
 
 
 
 
 
 
e411e71
8f24b44
 
43dd1ac
8f24b44
43dd1ac
 
73cc2a0
 
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
62
63
64
65
66
67
68
69
70
"use server"

import { revalidatePath } from "next/cache"

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)

  revalidatePath(`/studio/${ownerId}`)

  return task
}

/*
export const deleteVideo = async (ownerId: string, videoId: string) => {
  const task = await DELETE<GenericAPIResponse>(`${ownerId}/${videoId}`, { success: false })
  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) => {
  console.log("create new video")
  const task = await POST<VideoAPIRequest, Video>(
    ownerId,
    taskRequest,
    null as unknown as Video
  )

  // for doc see https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions
  revalidatePath(`/studio/${ownerId}`)
  return task
}