0220__migrate_images_to_attachments.js 1.0 KB

123456789101112131415161718192021222324252627
  1. module.exports = () => {
  2. const beccaLoader = require('../../src/becca/becca_loader.js');
  3. const becca = require('../../src/becca/becca.js');
  4. const cls = require('../../src/services/cls.js');
  5. const log = require('../../src/services/log.js');
  6. const sql = require('../../src/services/sql.js');
  7. cls.init(() => {
  8. // emergency disabling of image compression since it appears to make problems in migration to 0.61
  9. sql.execute(`UPDATE options SET value = 'false' WHERE name = 'compressImages'`);
  10. beccaLoader.load();
  11. for (const note of Object.values(becca.notes)) {
  12. try {
  13. const attachment = note.convertToParentAttachment({autoConversion: true});
  14. if (attachment) {
  15. log.info(`Auto-converted note '${note.noteId}' into attachment '${attachment.attachmentId}'.`);
  16. }
  17. }
  18. catch (e) {
  19. log.error(`Cannot convert note '${note.noteId}' to attachment: ${e.message} ${e.stack}`);
  20. }
  21. }
  22. });
  23. };