staticRouter.use(
STATIC_PATHS.WEBSEED,
cors(),
- express.static(CONFIG.STORAGE.VIDEOS_DIR)
+ express.static(CONFIG.STORAGE.VIDEOS_DIR, { fallthrough: false }) // 404 because we don't have this video
)
staticRouter.use(
- STATIC_PATHS.WEBSEED,
+ STATIC_PATHS.REDUNDANCY,
cors(),
- express.static(CONFIG.STORAGE.REDUNDANCY_DIR, { fallthrough: false }) // 404, because we don't have this video
+ express.static(CONFIG.STORAGE.REDUNDANCY_DIR, { fallthrough: false }) // 404 because we don't have this video
)
staticRouter.use(
THUMBNAILS: '/static/thumbnails/',
TORRENTS: '/static/torrents/',
WEBSEED: '/static/webseed/',
+ REDUNDANCY: '/static/redundancy/',
AVATARS: '/static/avatars/',
VIDEO_CAPTIONS: '/static/video-captions/'
}
const tmpPath = await downloadWebTorrentVideo({ magnetUri }, VIDEO_IMPORT_TIMEOUT)
- const destPath = join(CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename(file))
+ const destPath = join(CONFIG.STORAGE.REDUNDANCY_DIR, video.getVideoFilename(file))
await rename(tmpPath, destPath)
const createdModel = await VideoRedundancyModel.create({
expiresOn: this.buildNewExpiration(redundancy.minLifetime),
url: getVideoCacheFileActivityPubUrl(file),
- fileUrl: video.getVideoFileUrl(file, CONFIG.WEBSERVER.URL),
+ fileUrl: video.getVideoRedundancyUrl(file, CONFIG.WEBSERVER.URL),
strategy: redundancy.strategy,
videoFileId: file.id,
actorId: serverActor.id
import { ActorModel } from '../activitypub/actor'
import { getVideoSort, throwIfNotValid } from '../utils'
import { isActivityPubUrlValid, isUrlValid } from '../../helpers/custom-validators/activitypub/misc'
-import { CONFIG, CONSTRAINTS_FIELDS, VIDEO_EXT_MIMETYPE } from '../../initializers'
+import { CONFIG, CONSTRAINTS_FIELDS, STATIC_PATHS, VIDEO_EXT_MIMETYPE } from '../../initializers'
import { VideoFileModel } from '../video/video-file'
import { getServerActor } from '../../helpers/utils'
import { VideoModel } from '../video/video'
const logIdentifier = `${videoFile.Video.uuid}-${videoFile.resolution}`
logger.info('Removing duplicated video file %s.', logIdentifier)
- videoFile.Video.removeFile(videoFile)
+ videoFile.Video.removeFile(videoFile, true)
.catch(err => logger.error('Cannot delete %s files.', logIdentifier, { err }))
return undefined
.catch(err => logger.warn('Cannot delete preview %s.', previewPath, { err }))
}
- removeFile (videoFile: VideoFileModel) {
- const filePath = join(CONFIG.STORAGE.VIDEOS_DIR, this.getVideoFilename(videoFile))
+ removeFile (videoFile: VideoFileModel, isRedundancy = false) {
+ const baseDir = isRedundancy ? CONFIG.STORAGE.REDUNDANCY_DIR : CONFIG.STORAGE.VIDEOS_DIR
+
+ const filePath = join(baseDir, this.getVideoFilename(videoFile))
return remove(filePath)
.catch(err => logger.warn('Cannot delete file %s.', filePath, { err }))
}
return baseUrlHttp + STATIC_PATHS.WEBSEED + this.getVideoFilename(videoFile)
}
+ getVideoRedundancyUrl (videoFile: VideoFileModel, baseUrlHttp: string) {
+ return baseUrlHttp + STATIC_PATHS.REDUNDANCY + this.getVideoFilename(videoFile)
+ }
+
getVideoFileDownloadUrl (videoFile: VideoFileModel, baseUrlHttp: string) {
return baseUrlHttp + STATIC_DOWNLOAD_PATHS.VIDEOS + this.getVideoFilename(videoFile)
}
if (!videoUUID) videoUUID = video1Server2UUID
const webseeds = [
- 'http://localhost:9001/static/webseed/' + videoUUID,
+ 'http://localhost:9001/static/redundancy/' + videoUUID,
'http://localhost:9002/static/webseed/' + videoUUID
]
for (const file of video.files) {
checkMagnetWebseeds(file, webseeds, server)
- // Only servers 1 and 2 have the video
- if (server.serverNumber !== 3) {
- await makeGetRequest({
- url: server.url,
- statusCodeExpected: 200,
- path: '/static/webseed/' + `${videoUUID}-${file.resolution.id}.mp4`,
- contentType: null
- })
- }
+ await makeGetRequest({
+ url: servers[0].url,
+ statusCodeExpected: 200,
+ path: '/static/redundancy/' + `${videoUUID}-${file.resolution.id}.mp4`,
+ contentType: null
+ })
+ await makeGetRequest({
+ url: servers[1].url,
+ statusCodeExpected: 200,
+ path: '/static/webseed/' + `${videoUUID}-${file.resolution.id}.mp4`,
+ contentType: null
+ })
}
}
- for (const directory of [ 'test1', 'test2' ]) {
- const files = await readdir(join(root(), directory, 'videos'))
+ for (const directory of [ 'test1/redundancy', 'test2/videos' ]) {
+ const files = await readdir(join(root(), directory))
expect(files).to.have.length.at.least(4)
for (const resolution of [ 240, 360, 480, 720 ]) {
}
# Bypass PeerTube for performance reasons. Could be removed
- location /static/webseed {
+ location ~ ^/static/(webseed|redundancy)/ {
# Clients usually have 4 simultaneous webseed connections, so the real limit is 3MB/s per client
limit_rate 800k;
access_log off;
}
- alias /var/www/peertube/storage/videos;
+ root /var/www/peertube/storage;
+
+ rewrite ^/static/webseed/(.*)$ /videos/$1 break;
+ rewrite ^/static/redundancy/(.*)$ /redundancy/$1 break;
+
+ try_files $uri /;
}
# Websocket tracker