ニジカ投稿局 https://tv.nizika.tv
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

56 lines
1.9 KiB

  1. import * as Sequelize from 'sequelize'
  2. async function up (utils: {
  3. transaction: Sequelize.Transaction
  4. queryInterface: Sequelize.QueryInterface
  5. sequelize: Sequelize.Sequelize
  6. db: any
  7. }): Promise<void> {
  8. for (const column of [ 'filename', 'fileUrl', 'torrentFilename', 'torrentUrl' ]) {
  9. const data = {
  10. type: Sequelize.STRING,
  11. allowNull: true,
  12. defaultValue: null
  13. }
  14. await utils.queryInterface.addColumn('videoFile', column, data)
  15. }
  16. // Generate filenames for webtorrent files
  17. {
  18. const webtorrentQuery = `SELECT "videoFile".id, "video".uuid, "videoFile".resolution, "videoFile".extname ` +
  19. `FROM video INNER JOIN "videoFile" ON "videoFile"."videoId" = video.id`
  20. const query = `UPDATE "videoFile" ` +
  21. `SET filename = t.uuid || '-' || t.resolution || t.extname, ` +
  22. `"torrentFilename" = t.uuid || '-' || t.resolution || '.torrent' ` +
  23. `FROM (${webtorrentQuery}) AS t WHERE t.id = "videoFile"."id"`
  24. await utils.sequelize.query(query)
  25. }
  26. // Generate filenames for HLS files
  27. {
  28. const hlsQuery = `SELECT "videoFile".id, "video".uuid, "videoFile".resolution, "videoFile".extname ` +
  29. `FROM video ` +
  30. `INNER JOIN "videoStreamingPlaylist" ON "videoStreamingPlaylist"."videoId" = video.id ` +
  31. `INNER JOIN "videoFile" ON "videoFile"."videoStreamingPlaylistId" = "videoStreamingPlaylist".id`
  32. const query = `UPDATE "videoFile" ` +
  33. `SET filename = t.uuid || '-' || t.resolution || '-fragmented' || t.extname, ` +
  34. `"torrentFilename" = t.uuid || '-' || t.resolution || '-hls.torrent' ` +
  35. `FROM (${hlsQuery}) AS t WHERE t.id = "videoFile"."id"`
  36. await utils.sequelize.query(query)
  37. }
  38. }
  39. function down (options) {
  40. throw new Error('Not implemented.')
  41. }
  42. export {
  43. up,
  44. down
  45. }