]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-main/account/actor.model.ts
Add ability to cancel & delete video imports
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / account / actor.model.ts
1 import { getAbsoluteAPIUrl } from '@app/helpers'
2 import { Actor as ServerActor, ActorImage } from '@shared/models'
3
4 export abstract class Actor implements ServerActor {
5 id: number
6 name: string
7
8 host: string
9 url: string
10
11 followingCount: number
12 followersCount: number
13
14 createdAt: Date | string
15
16 avatar: ActorImage
17
18 isLocal: boolean
19
20 static GET_ACTOR_AVATAR_URL (actor: { avatar?: { url?: string, path: string } }) {
21 if (actor?.avatar?.url) return actor.avatar.url
22
23 if (actor?.avatar) {
24 const absoluteAPIUrl = getAbsoluteAPIUrl()
25
26 return absoluteAPIUrl + actor.avatar.path
27 }
28
29 return ''
30 }
31
32 static CREATE_BY_STRING (accountName: string, host: string, forceHostname = false) {
33 const absoluteAPIUrl = getAbsoluteAPIUrl()
34 const thisHost = new URL(absoluteAPIUrl).host
35
36 if (host.trim() === thisHost && !forceHostname) return accountName
37
38 return accountName + '@' + host
39 }
40
41 static IS_LOCAL (host: string) {
42 const absoluteAPIUrl = getAbsoluteAPIUrl()
43 const thisHost = new URL(absoluteAPIUrl).host
44
45 return host.trim() === thisHost
46 }
47
48 protected constructor (hash: Partial<ServerActor>) {
49 this.id = hash.id
50 this.url = hash.url ?? ''
51 this.name = hash.name ?? ''
52 this.host = hash.host ?? ''
53 this.followingCount = hash.followingCount
54 this.followersCount = hash.followersCount
55
56 if (hash.createdAt) this.createdAt = new Date(hash.createdAt.toString())
57
58 this.avatar = hash.avatar
59 this.isLocal = Actor.IS_LOCAL(this.host)
60 }
61 }