diff options
Diffstat (limited to 'server/lib/user.ts')
-rw-r--r-- | server/lib/user.ts | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/server/lib/user.ts b/server/lib/user.ts index 9b0a0a2f1..936403692 100644 --- a/server/lib/user.ts +++ b/server/lib/user.ts | |||
@@ -1,19 +1,21 @@ | |||
1 | import { Transaction } from 'sequelize/types' | 1 | import { Transaction } from 'sequelize/types' |
2 | import { v4 as uuidv4 } from 'uuid' | 2 | import { buildUUID } from '@server/helpers/uuid' |
3 | import { UserModel } from '@server/models/account/user' | 3 | import { UserModel } from '@server/models/user/user' |
4 | import { MActorDefault } from '@server/types/models/actor' | ||
4 | import { ActivityPubActorType } from '../../shared/models/activitypub' | 5 | import { ActivityPubActorType } from '../../shared/models/activitypub' |
5 | import { UserNotificationSetting, UserNotificationSettingValue } from '../../shared/models/users' | 6 | import { UserNotificationSetting, UserNotificationSettingValue } from '../../shared/models/users' |
6 | import { SERVER_ACTOR_NAME, WEBSERVER } from '../initializers/constants' | 7 | import { SERVER_ACTOR_NAME, WEBSERVER } from '../initializers/constants' |
7 | import { sequelizeTypescript } from '../initializers/database' | 8 | import { sequelizeTypescript } from '../initializers/database' |
8 | import { AccountModel } from '../models/account/account' | 9 | import { AccountModel } from '../models/account/account' |
9 | import { UserNotificationSettingModel } from '../models/account/user-notification-setting' | 10 | import { ActorModel } from '../models/actor/actor' |
10 | import { ActorModel } from '../models/activitypub/actor' | 11 | import { UserNotificationSettingModel } from '../models/user/user-notification-setting' |
11 | import { MAccountDefault, MActorDefault, MChannelActor } from '../types/models' | 12 | import { MAccountDefault, MChannelActor } from '../types/models' |
12 | import { MUser, MUserDefault, MUserId } from '../types/models/user' | 13 | import { MUser, MUserDefault, MUserId } from '../types/models/user' |
13 | import { buildActorInstance, generateAndSaveActorKeys } from './activitypub/actor' | 14 | import { generateAndSaveActorKeys } from './activitypub/actors' |
14 | import { getLocalAccountActivityPubUrl } from './activitypub/url' | 15 | import { getLocalAccountActivityPubUrl } from './activitypub/url' |
15 | import { Emailer } from './emailer' | 16 | import { Emailer } from './emailer' |
16 | import { LiveManager } from './live-manager' | 17 | import { LiveQuotaStore } from './live/live-quota-store' |
18 | import { buildActorInstance } from './local-actor' | ||
17 | import { Redis } from './redis' | 19 | import { Redis } from './redis' |
18 | import { createLocalVideoChannel } from './video-channel' | 20 | import { createLocalVideoChannel } from './video-channel' |
19 | import { createWatchLaterPlaylist } from './video-playlist' | 21 | import { createWatchLaterPlaylist } from './video-playlist' |
@@ -42,11 +44,11 @@ async function createUserAccountAndChannelAndPlaylist (parameters: { | |||
42 | displayName: userDisplayName, | 44 | displayName: userDisplayName, |
43 | userId: userCreated.id, | 45 | userId: userCreated.id, |
44 | applicationId: null, | 46 | applicationId: null, |
45 | t: t | 47 | t |
46 | }) | 48 | }) |
47 | userCreated.Account = accountCreated | 49 | userCreated.Account = accountCreated |
48 | 50 | ||
49 | const channelAttributes = await buildChannelAttributes(userCreated, channelNames) | 51 | const channelAttributes = await buildChannelAttributes(userCreated, t, channelNames) |
50 | const videoChannel = await createLocalVideoChannel(channelAttributes, accountCreated, t) | 52 | const videoChannel = await createLocalVideoChannel(channelAttributes, accountCreated, t) |
51 | 53 | ||
52 | const videoPlaylist = await createWatchLaterPlaylist(accountCreated, t) | 54 | const videoPlaylist = await createWatchLaterPlaylist(accountCreated, t) |
@@ -127,7 +129,7 @@ async function getOriginalVideoFileTotalFromUser (user: MUserId) { | |||
127 | 129 | ||
128 | const base = await UserModel.getTotalRawQuery(query, user.id) | 130 | const base = await UserModel.getTotalRawQuery(query, user.id) |
129 | 131 | ||
130 | return base + LiveManager.Instance.getLiveQuotaUsedByUser(user.id) | 132 | return base + LiveQuotaStore.Instance.getLiveQuotaOf(user.id) |
131 | } | 133 | } |
132 | 134 | ||
133 | // Returns cumulative size of all video files uploaded in the last 24 hours. | 135 | // Returns cumulative size of all video files uploaded in the last 24 hours. |
@@ -141,10 +143,10 @@ async function getOriginalVideoFileTotalDailyFromUser (user: MUserId) { | |||
141 | 143 | ||
142 | const base = await UserModel.getTotalRawQuery(query, user.id) | 144 | const base = await UserModel.getTotalRawQuery(query, user.id) |
143 | 145 | ||
144 | return base + LiveManager.Instance.getLiveQuotaUsedByUser(user.id) | 146 | return base + LiveQuotaStore.Instance.getLiveQuotaOf(user.id) |
145 | } | 147 | } |
146 | 148 | ||
147 | async function isAbleToUploadVideo (userId: number, size: number) { | 149 | async function isAbleToUploadVideo (userId: number, newVideoSize: number) { |
148 | const user = await UserModel.loadById(userId) | 150 | const user = await UserModel.loadById(userId) |
149 | 151 | ||
150 | if (user.videoQuota === -1 && user.videoQuotaDaily === -1) return Promise.resolve(true) | 152 | if (user.videoQuota === -1 && user.videoQuotaDaily === -1) return Promise.resolve(true) |
@@ -154,8 +156,8 @@ async function isAbleToUploadVideo (userId: number, size: number) { | |||
154 | getOriginalVideoFileTotalDailyFromUser(user) | 156 | getOriginalVideoFileTotalDailyFromUser(user) |
155 | ]) | 157 | ]) |
156 | 158 | ||
157 | const uploadedTotal = size + totalBytes | 159 | const uploadedTotal = newVideoSize + totalBytes |
158 | const uploadedDaily = size + totalBytesDaily | 160 | const uploadedDaily = newVideoSize + totalBytesDaily |
159 | 161 | ||
160 | if (user.videoQuotaDaily === -1) return uploadedTotal < user.videoQuota | 162 | if (user.videoQuotaDaily === -1) return uploadedTotal < user.videoQuota |
161 | if (user.videoQuota === -1) return uploadedDaily < user.videoQuotaDaily | 163 | if (user.videoQuota === -1) return uploadedDaily < user.videoQuotaDaily |
@@ -201,14 +203,14 @@ function createDefaultUserNotificationSettings (user: MUserId, t: Transaction | | |||
201 | return UserNotificationSettingModel.create(values, { transaction: t }) | 203 | return UserNotificationSettingModel.create(values, { transaction: t }) |
202 | } | 204 | } |
203 | 205 | ||
204 | async function buildChannelAttributes (user: MUser, channelNames?: ChannelNames) { | 206 | async function buildChannelAttributes (user: MUser, transaction?: Transaction, channelNames?: ChannelNames) { |
205 | if (channelNames) return channelNames | 207 | if (channelNames) return channelNames |
206 | 208 | ||
207 | let channelName = user.username + '_channel' | 209 | let channelName = user.username + '_channel' |
208 | 210 | ||
209 | // Conflict, generate uuid instead | 211 | // Conflict, generate uuid instead |
210 | const actor = await ActorModel.loadLocalByName(channelName) | 212 | const actor = await ActorModel.loadLocalByName(channelName, transaction) |
211 | if (actor) channelName = uuidv4() | 213 | if (actor) channelName = buildUUID() |
212 | 214 | ||
213 | const videoChannelDisplayName = `Main ${user.username} channel` | 215 | const videoChannelDisplayName = `Main ${user.username} channel` |
214 | 216 | ||