Sanitize url to not end with implicit ports
[oweals/peertube.git] / server / initializers / migrations / 0140-actor-url.ts
1 import * as Sequelize from 'sequelize'
2 import { DataType } from 'sequelize-typescript'
3 import { createPrivateAndPublicKeys } from '../../helpers'
4 import { CONFIG } from '../constants'
5
6 async function up (utils: {
7   transaction: Sequelize.Transaction,
8   queryInterface: Sequelize.QueryInterface,
9   sequelize: Sequelize.Sequelize
10 }): Promise<void> {
11   const toReplace = CONFIG.WEBSERVER.HOSTNAME + ':443'
12   const by = CONFIG.WEBSERVER.HOST
13   const replacer = column => `replace("${column}", '${toReplace}', '${by}')`
14
15   {
16     const query = `UPDATE video SET url = ${replacer('url')}`
17     await utils.sequelize.query(query)
18   }
19
20   {
21     const query = `
22       UPDATE actor SET url = ${replacer('url')}, "inboxUrl" = ${replacer('inboxUrl')}, "outboxUrl" = ${replacer('outboxUrl')},
23       "sharedInboxUrl" = ${replacer('sharedInboxUrl')}, "followersUrl" = ${replacer('followersUrl')},
24       "followingUrl" = ${replacer('followingUrl')}
25     `
26     await utils.sequelize.query(query)
27   }
28
29   {
30     const query = `UPDATE server SET host = replace(host, ':443', '')`
31     await utils.sequelize.query(query)
32   }
33 }
34
35 function down (options) {
36   throw new Error('Not implemented.')
37 }
38
39 export {
40   up,
41   down
42 }