● Zion Boggan
repos/Stepping App/packages/api/src/services.ts
zionboggan.com ↗
42 lines · typescript
History for this file →
1
 
2
export interface UploadTarget {
3
  uploadUrl: string;
4
  assetId: string;
5
}
6
 
7
export interface LiveStreamHandle {
8
  streamKey: string;
9
  playbackId: string;
10
  ingestUrl: string;
11
}
12
 
13
export interface MediaService {
14
  createDirectUpload(opts: { ownerId: string }): Promise<UploadTarget>;
15
  getPlaybackUrl(assetId: string): Promise<string | null>;
16
  createLiveStream(opts: { ownerId: string }): Promise<LiveStreamHandle>;
17
}
18
 
19
export interface ModerationResult {
20
  allow: boolean;
21
  reason?: string;
22
}
23
 
24
export interface ModerationService {
25
  checkText(text: string): Promise<ModerationResult>;
26
  checkAsset(url: string): Promise<ModerationResult>;
27
}
28
 
29
const notWired = (what: string) => (): never => {
30
  throw new Error(`${what} not wired yet (Phase 2: connect Mux).`);
31
};
32
 
33
export const noopMedia: MediaService = {
34
  createDirectUpload: notWired("MediaService.createDirectUpload"),
35
  getPlaybackUrl: async () => null,
36
  createLiveStream: notWired("MediaService.createLiveStream"),
37
};
38
 
39
export const allowAllModeration: ModerationService = {
40
  checkText: async () => ({ allow: true }),
41
  checkAsset: async () => ({ allow: true }),
42
};