From 0749c31100cd731c556d50147df404461473eba5 Mon Sep 17 00:00:00 2001 From: Philip Molares Date: Mon, 22 Jun 2026 23:06:17 +0200 Subject: [PATCH] refactor: remove Temp This was a very old way of migrating the history and is no longer needed. Signed-off-by: Philip Molares --- lib/migrations/20260622225700-remove-temp.js | 19 ++++++ lib/models/temp.js | 18 ----- lib/web/statusRouter.js | 69 -------------------- public/js/cover.js | 1 - public/js/history.js | 35 ---------- 5 files changed, 19 insertions(+), 123 deletions(-) create mode 100644 lib/migrations/20260622225700-remove-temp.js delete mode 100644 lib/models/temp.js diff --git a/lib/migrations/20260622225700-remove-temp.js b/lib/migrations/20260622225700-remove-temp.js new file mode 100644 index 00000000..2c6b7e63 --- /dev/null +++ b/lib/migrations/20260622225700-remove-temp.js @@ -0,0 +1,19 @@ +'use strict' + +module.exports = { + up: function (queryInterface, Sequelize) { + return queryInterface.dropTable('Temp') + }, + + down: function (queryInterface, Sequelize) { + return queryInterface.createTable('Temp', { + id: { + type: Sequelize.STRING, + primaryKey: true + }, + date: Sequelize.TEXT, + createdAt: Sequelize.DATE, + updatedAt: Sequelize.DATE + }) + } +} diff --git a/lib/models/temp.js b/lib/models/temp.js deleted file mode 100644 index bfc88a3f..00000000 --- a/lib/models/temp.js +++ /dev/null @@ -1,18 +0,0 @@ -'use strict' -// external modules -const nanoid = require('nanoid') - -module.exports = function (sequelize, DataTypes) { - const Temp = sequelize.define('Temp', { - id: { - type: DataTypes.STRING, - primaryKey: true, - defaultValue: nanoid.nanoid - }, - data: { - type: DataTypes.TEXT - } - }) - - return Temp -} diff --git a/lib/web/statusRouter.js b/lib/web/statusRouter.js index 10716150..bc5702c2 100644 --- a/lib/web/statusRouter.js +++ b/lib/web/statusRouter.js @@ -5,10 +5,6 @@ const Router = require('express').Router const errors = require('../errors') const realtime = require('../realtime') const config = require('../config') -const models = require('../models') -const logger = require('../logger') - -const { urlencodedParser } = require('./utils') const statusRouter = module.exports = Router() @@ -36,71 +32,6 @@ statusRouter.get('/status', function (req, res, next) { res.send(data) }) }) -// get status -statusRouter.get('/temp', function (req, res) { - const host = req.get('host') - if (config.allowOrigin.indexOf(host) === -1) { - errors.errorForbidden(res) - } else { - const tempid = req.query.tempid - if (!tempid) { - errors.errorForbidden(res) - } else { - models.Temp.findOne({ - where: { - id: tempid - } - }).then(function (temp) { - if (!temp) { - errors.errorNotFound(res) - } else { - res.header('Access-Control-Allow-Origin', '*') - res.send({ - temp: temp.data - }) - temp.destroy().catch(function (err) { - if (err) { - logger.error('remove temp failed: ' + err) - } - }) - } - }).catch(function (err) { - logger.error(err) - return errors.errorInternalError(res) - }) - } - } -}) -// post status -statusRouter.post('/temp', urlencodedParser, function (req, res) { - const host = req.get('host') - if (config.allowOrigin.indexOf(host) === -1) { - errors.errorForbidden(res) - } else { - const data = req.body.data - if (!data) { - errors.errorForbidden(res) - } else { - logger.debug(`SERVER received temp from [${host}]: ${req.body.data}`) - models.Temp.create({ - data - }).then(function (temp) { - if (temp) { - res.header('Access-Control-Allow-Origin', '*') - res.send({ - status: 'ok', - id: temp.id - }) - } else { - errors.errorInternalError(res) - } - }).catch(function (err) { - logger.error(err) - return errors.errorInternalError(res) - }) - } - } -}) statusRouter.get('/config', function (req, res) { const data = { diff --git a/public/js/cover.js b/public/js/cover.js index 77bc3fb6..d578b150 100644 --- a/public/js/cover.js +++ b/public/js/cover.js @@ -61,7 +61,6 @@ const options = { } const historyList = new List('history', options) -window.migrateHistoryFromTempCallback = pageInit setloginStateChangeEvent(pageInit) pageInit() diff --git a/public/js/history.js b/public/js/history.js index b262323e..58d94b9e 100644 --- a/public/js/history.js +++ b/public/js/history.js @@ -3,7 +3,6 @@ import store from 'store' import LZString from 'lz-string' -import url from 'wurl' import { checkNoteIdValid, @@ -19,40 +18,6 @@ import { urlpath } from './lib/config' -window.migrateHistoryFromTempCallback = null - -migrateHistoryFromTemp() - -function migrateHistoryFromTemp () { - if (url('#tempid')) { - $.get(`${serverurl}/temp`, { - tempid: url('#tempid') - }) - .done(data => { - if (data && data.temp) { - getStorageHistory(olddata => { - if (!olddata || olddata.length === 0) { - saveHistoryToStorage(JSON.parse(data.temp)) - } - }) - } - }) - .always(() => { - let hash = location.hash.split('#')[1] - hash = hash.split('&') - for (let i = 0; i < hash.length; i++) { - if (hash[i].indexOf('tempid') === 0) { - hash.splice(i, 1) - i-- - } - } - hash = hash.join('&') - location.hash = hash - if (window.migrateHistoryFromTempCallback) { window.migrateHistoryFromTempCallback() } - }) - } -} - export function saveHistory (notehistory) { checkIfAuth( () => {