Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Framasoft
PeerTube
PeerTube
Commits
8e3b46de
Verified
Commit
8e3b46de
authored
Oct 22, 2021
by
kontrollanten
Committed by
Chocobozzz
Nov 04, 2021
Browse files
add migrate-to-object-storage-script
closes #4467
parent
dd6d2a7c
Changes
4
Hide whitespace changes
Inline
Side-by-side
scripts/migrate-to-object-storage.ts
0 → 100644
View file @
8e3b46de
import
{
registerTSPaths
}
from
'
../server/helpers/register-ts-paths
'
registerTSPaths
()
import
{
program
}
from
'
commander
'
import
{
VideoModel
}
from
'
@server/models/video/video
'
import
{
initDatabaseModels
}
from
'
@server/initializers/database
'
import
{
VideoState
,
VideoStorage
}
from
'
@shared/models
'
import
{
moveToNextState
}
from
'
@server/lib/video-state
'
import
{
JobQueue
}
from
'
@server/lib/job-queue
'
program
.
description
(
'
Migrate videos to object storage.
'
)
.
parse
(
process
.
argv
)
run
()
.
then
(()
=>
process
.
exit
(
0
))
.
catch
(
err
=>
console
.
error
(
err
))
async
function
run
()
{
await
initDatabaseModels
(
true
)
JobQueue
.
Instance
.
init
()
const
videos
=
await
VideoModel
.
listLocal
()
const
withFiles
=
(
await
Promise
.
all
(
videos
.
map
(
video
=>
VideoModel
.
loadWithFiles
(
video
.
id
))))
.
filter
(
video
=>
video
.
VideoFiles
.
find
(
vf
=>
vf
.
storage
===
VideoStorage
.
FILE_SYSTEM
)
||
video
.
VideoStreamingPlaylists
.
find
(
sp
=>
sp
.
storage
===
VideoStorage
.
FILE_SYSTEM
)
)
for
(
const
video
of
withFiles
)
{
video
.
state
=
VideoState
.
TO_MIGRATE_TO_EXTERNAL_STORAGE
await
video
.
save
()
await
moveToNextState
(
video
,
false
)
console
.
log
(
`Created move-to-object-storage job for
${
video
.
name
}
.`
)
}
}
server/initializers/constants.ts
View file @
8e3b46de
...
...
@@ -419,7 +419,8 @@ const VIDEO_STATES: { [ id in VideoState ]: string } = {
[
VideoState
.
TO_IMPORT
]:
'
To import
'
,
[
VideoState
.
WAITING_FOR_LIVE
]:
'
Waiting for livestream
'
,
[
VideoState
.
LIVE_ENDED
]:
'
Livestream ended
'
,
[
VideoState
.
TO_MOVE_TO_EXTERNAL_STORAGE
]:
'
To move to an external storage
'
[
VideoState
.
TO_MOVE_TO_EXTERNAL_STORAGE
]:
'
To move to an external storage
'
,
[
VideoState
.
TO_MIGRATE_TO_EXTERNAL_STORAGE
]:
'
To migrate to an external storage
'
}
const
VIDEO_IMPORT_STATES
:
{
[
id
in
VideoImportState
]:
string
}
=
{
...
...
server/lib/video-state.ts
View file @
8e3b46de
...
...
@@ -11,6 +11,10 @@ import { Notifier } from './notifier'
import
{
addMoveToObjectStorageJob
}
from
'
./video
'
function
buildNextVideoState
(
currentState
?:
VideoState
)
{
if
(
currentState
===
VideoState
.
TO_MIGRATE_TO_EXTERNAL_STORAGE
)
{
return
VideoState
.
TO_MOVE_TO_EXTERNAL_STORAGE
}
if
(
currentState
===
VideoState
.
PUBLISHED
)
{
throw
new
Error
(
'
Video is already in its final state
'
)
}
...
...
shared/models/videos/video-state.enum.ts
View file @
8e3b46de
...
...
@@ -4,5 +4,6 @@ export const enum VideoState {
TO_IMPORT
=
3
,
WAITING_FOR_LIVE
=
4
,
LIVE_ENDED
=
5
,
TO_MOVE_TO_EXTERNAL_STORAGE
=
6
TO_MOVE_TO_EXTERNAL_STORAGE
=
6
,
TO_MIGRATE_TO_EXTERNAL_STORAGE
=
7
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment