aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/videos/videos.ts
diff options
context:
space:
mode:
authorlutangar <johan.dufour@gmail.com>2021-11-02 19:11:20 +0100
committerChocobozzz <chocobozzz@cpy.re>2021-12-16 10:08:43 +0100
commit06aad80165d09a8863ab8103149a8ff518b10641 (patch)
treea97fa31f3ade29ff807ca1b77704eb47085ab99d /shared/extra-utils/videos/videos.ts
parent854f533c12bd2b88c70f9d5aeab770059e9a6861 (diff)
downloadPeerTube-06aad80165d09a8863ab8103149a8ff518b10641.tar.gz
PeerTube-06aad80165d09a8863ab8103149a8ff518b10641.tar.zst
PeerTube-06aad80165d09a8863ab8103149a8ff518b10641.zip
chore(refactor): remove shared folder dependencies to the server
Many files from the `shared` folder were importing files from the `server` folder. When attempting to use Typescript project references to describe dependencies, it highlighted a circular dependency beetween `shared` <-> `server`. The Typescript project forbid such usages. Using project references greatly improve performance by rebuilding only the updated project and not all source files. > see https://www.typescriptlang.org/docs/handbook/project-references.html
Diffstat (limited to 'shared/extra-utils/videos/videos.ts')
-rw-r--r--shared/extra-utils/videos/videos.ts150
1 files changed, 0 insertions, 150 deletions
diff --git a/shared/extra-utils/videos/videos.ts b/shared/extra-utils/videos/videos.ts
index c05c2be6c..2c3464aa8 100644
--- a/shared/extra-utils/videos/videos.ts
+++ b/shared/extra-utils/videos/videos.ts
@@ -3,12 +3,7 @@
3import { expect } from 'chai' 3import { expect } from 'chai'
4import { pathExists, readdir } from 'fs-extra' 4import { pathExists, readdir } from 'fs-extra'
5import { basename, join } from 'path' 5import { basename, join } from 'path'
6import { getLowercaseExtension } from '@server/helpers/core-utils'
7import { uuidRegex } from '@shared/core-utils'
8import { HttpStatusCode, VideoCaption, VideoDetails } from '@shared/models' 6import { HttpStatusCode, VideoCaption, VideoDetails } from '@shared/models'
9import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../server/initializers/constants'
10import { dateIsValid, testImage, webtorrentAdd } from '../miscs'
11import { makeRawRequest } from '../requests/requests'
12import { waitJobs } from '../server' 7import { waitJobs } from '../server'
13import { PeerTubeServer } from '../server/server' 8import { PeerTubeServer } from '../server/server'
14import { VideoEdit } from './videos-command' 9import { VideoEdit } from './videos-command'
@@ -85,150 +80,6 @@ function checkUploadVideoParam (
85 : server.videos.buildResumeUpload({ token, attributes, expectedStatus }) 80 : server.videos.buildResumeUpload({ token, attributes, expectedStatus })
86} 81}
87 82
88async function completeVideoCheck (
89 server: PeerTubeServer,
90 video: any,
91 attributes: {
92 name: string
93 category: number
94 licence: number
95 language: string
96 nsfw: boolean
97 commentsEnabled: boolean
98 downloadEnabled: boolean
99 description: string
100 publishedAt?: string
101 support: string
102 originallyPublishedAt?: string
103 account: {
104 name: string
105 host: string
106 }
107 isLocal: boolean
108 tags: string[]
109 privacy: number
110 likes?: number
111 dislikes?: number
112 duration: number
113 channel: {
114 displayName: string
115 name: string
116 description: string
117 isLocal: boolean
118 }
119 fixture: string
120 files: {
121 resolution: number
122 size: number
123 }[]
124 thumbnailfile?: string
125 previewfile?: string
126 }
127) {
128 if (!attributes.likes) attributes.likes = 0
129 if (!attributes.dislikes) attributes.dislikes = 0
130
131 const host = new URL(server.url).host
132 const originHost = attributes.account.host
133
134 expect(video.name).to.equal(attributes.name)
135 expect(video.category.id).to.equal(attributes.category)
136 expect(video.category.label).to.equal(attributes.category !== null ? VIDEO_CATEGORIES[attributes.category] : 'Misc')
137 expect(video.licence.id).to.equal(attributes.licence)
138 expect(video.licence.label).to.equal(attributes.licence !== null ? VIDEO_LICENCES[attributes.licence] : 'Unknown')
139 expect(video.language.id).to.equal(attributes.language)
140 expect(video.language.label).to.equal(attributes.language !== null ? VIDEO_LANGUAGES[attributes.language] : 'Unknown')
141 expect(video.privacy.id).to.deep.equal(attributes.privacy)
142 expect(video.privacy.label).to.deep.equal(VIDEO_PRIVACIES[attributes.privacy])
143 expect(video.nsfw).to.equal(attributes.nsfw)
144 expect(video.description).to.equal(attributes.description)
145 expect(video.account.id).to.be.a('number')
146 expect(video.account.host).to.equal(attributes.account.host)
147 expect(video.account.name).to.equal(attributes.account.name)
148 expect(video.channel.displayName).to.equal(attributes.channel.displayName)
149 expect(video.channel.name).to.equal(attributes.channel.name)
150 expect(video.likes).to.equal(attributes.likes)
151 expect(video.dislikes).to.equal(attributes.dislikes)
152 expect(video.isLocal).to.equal(attributes.isLocal)
153 expect(video.duration).to.equal(attributes.duration)
154 expect(video.url).to.contain(originHost)
155 expect(dateIsValid(video.createdAt)).to.be.true
156 expect(dateIsValid(video.publishedAt)).to.be.true
157 expect(dateIsValid(video.updatedAt)).to.be.true
158
159 if (attributes.publishedAt) {
160 expect(video.publishedAt).to.equal(attributes.publishedAt)
161 }
162
163 if (attributes.originallyPublishedAt) {
164 expect(video.originallyPublishedAt).to.equal(attributes.originallyPublishedAt)
165 } else {
166 expect(video.originallyPublishedAt).to.be.null
167 }
168
169 const videoDetails = await server.videos.get({ id: video.uuid })
170
171 expect(videoDetails.files).to.have.lengthOf(attributes.files.length)
172 expect(videoDetails.tags).to.deep.equal(attributes.tags)
173 expect(videoDetails.account.name).to.equal(attributes.account.name)
174 expect(videoDetails.account.host).to.equal(attributes.account.host)
175 expect(video.channel.displayName).to.equal(attributes.channel.displayName)
176 expect(video.channel.name).to.equal(attributes.channel.name)
177 expect(videoDetails.channel.host).to.equal(attributes.account.host)
178 expect(videoDetails.channel.isLocal).to.equal(attributes.channel.isLocal)
179 expect(dateIsValid(videoDetails.channel.createdAt.toString())).to.be.true
180 expect(dateIsValid(videoDetails.channel.updatedAt.toString())).to.be.true
181 expect(videoDetails.commentsEnabled).to.equal(attributes.commentsEnabled)
182 expect(videoDetails.downloadEnabled).to.equal(attributes.downloadEnabled)
183
184 for (const attributeFile of attributes.files) {
185 const file = videoDetails.files.find(f => f.resolution.id === attributeFile.resolution)
186 expect(file).not.to.be.undefined
187
188 let extension = getLowercaseExtension(attributes.fixture)
189 // Transcoding enabled: extension will always be .mp4
190 if (attributes.files.length > 1) extension = '.mp4'
191
192 expect(file.magnetUri).to.have.lengthOf.above(2)
193
194 expect(file.torrentDownloadUrl).to.match(new RegExp(`http://${host}/download/torrents/${uuidRegex}-${file.resolution.id}.torrent`))
195 expect(file.torrentUrl).to.match(new RegExp(`http://${host}/lazy-static/torrents/${uuidRegex}-${file.resolution.id}.torrent`))
196
197 expect(file.fileUrl).to.match(new RegExp(`http://${originHost}/static/webseed/${uuidRegex}-${file.resolution.id}${extension}`))
198 expect(file.fileDownloadUrl).to.match(new RegExp(`http://${originHost}/download/videos/${uuidRegex}-${file.resolution.id}${extension}`))
199
200 await Promise.all([
201 makeRawRequest(file.torrentUrl, 200),
202 makeRawRequest(file.torrentDownloadUrl, 200),
203 makeRawRequest(file.metadataUrl, 200)
204 ])
205
206 expect(file.resolution.id).to.equal(attributeFile.resolution)
207 expect(file.resolution.label).to.equal(attributeFile.resolution + 'p')
208
209 const minSize = attributeFile.size - ((10 * attributeFile.size) / 100)
210 const maxSize = attributeFile.size + ((10 * attributeFile.size) / 100)
211 expect(
212 file.size,
213 'File size for resolution ' + file.resolution.label + ' outside confidence interval (' + minSize + '> size <' + maxSize + ')'
214 ).to.be.above(minSize).and.below(maxSize)
215
216 const torrent = await webtorrentAdd(file.magnetUri, true)
217 expect(torrent.files).to.be.an('array')
218 expect(torrent.files.length).to.equal(1)
219 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
220 expect(torrent.files[0].name).to.equal(`${videoDetails.name} ${file.resolution.id}p${extension}`)
221 }
222
223 expect(videoDetails.thumbnailPath).to.exist
224 await testImage(server.url, attributes.thumbnailfile || attributes.fixture, videoDetails.thumbnailPath)
225
226 if (attributes.previewfile) {
227 expect(videoDetails.previewPath).to.exist
228 await testImage(server.url, attributes.previewfile, videoDetails.previewPath)
229 }
230}
231
232// serverNumber starts from 1 83// serverNumber starts from 1
233async function uploadRandomVideoOnServers ( 84async function uploadRandomVideoOnServers (
234 servers: PeerTubeServer[], 85 servers: PeerTubeServer[],
@@ -247,7 +98,6 @@ async function uploadRandomVideoOnServers (
247 98
248export { 99export {
249 checkUploadVideoParam, 100 checkUploadVideoParam,
250 completeVideoCheck,
251 uploadRandomVideoOnServers, 101 uploadRandomVideoOnServers,
252 checkVideoFilesWereRemoved, 102 checkVideoFilesWereRemoved,
253 saveVideoInServers 103 saveVideoInServers