File size: 836 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const replace = require('string-replace-to-array');
const MARKDOWN_LINK = /(?:\[(.*?)\]\((.*?)\))/g;

const removeMarkdownLinks = text => {
  if (!text || typeof text !== 'string') return text;
  return replace(text, MARKDOWN_LINK, (fullLink, text, url) => url).join('');
};

exports.up = function(r, conn) {
  return r
    .table('messages')
    .withFields('id', 'content')
    .run(conn)
    .then(cursor => cursor.toArray())
    .then(messages =>
      Promise.all(
        messages.map(message =>
          r
            .table('messages')
            .get(message.id)
            .update({
              content: {
                body: removeMarkdownLinks(message.content.body),
              },
            })
            .run(conn)
        )
      )
    );
};

exports.down = function(r, conn) {
  return Promise.resolve();
};