react-code-dataset / spectrum /api /migrations /20170702194221-fix-images.js
Devendra174's picture
Upload folder using huggingface_hub
1e92f2d verified
const MARKDOWN_LINK = /(?:\[(.*?)\]\((.*?)\))/g;
exports.up = function(r, conn) {
return (
// The last migration fucked images up in production
// so this one fixes them again 😅
r
.table('messages')
.filter({ messageType: 'media' })
.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: MARKDOWN_LINK.test(message.content.body)
? message.content.body.replace(MARKDOWN_LINK, '$2')
: message.content.body,
},
})
.run(conn)
)
)
)
);
};
exports.down = function(r, conn) {
// Can't really undo just this change so we don't bother
return Promise.resolve();
};