diff --git a/lib/migrations/20200104215332-remove-temp-table.js b/lib/migrations/20200104215332-remove-temp-table.js new file mode 100644 index 00000000..eb743337 --- /dev/null +++ b/lib/migrations/20200104215332-remove-temp-table.js @@ -0,0 +1,26 @@ +'use strict' + +module.exports = { + up: (queryInterface, Sequelize) => { + return queryInterface.dropTable('Temp') + /* + Add altering commands here. + Return a promise to correctly handle asynchronicity. + + Example: + return queryInterface.createTable('users', { id: Sequelize.INTEGER }); + */ + }, + + down: (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 2ad23fb5..00000000 --- a/lib/models/temp.js +++ /dev/null @@ -1,18 +0,0 @@ -'use strict' -// external modules -var shortId = require('shortid') - -module.exports = function (sequelize, DataTypes) { - var Temp = sequelize.define('Temp', { - id: { - type: DataTypes.STRING, - primaryKey: true, - defaultValue: shortId.generate - }, - data: { - type: DataTypes.TEXT - } - }) - - return Temp -} diff --git a/lib/web/statusRouter.js b/lib/web/statusRouter.js index ae891ad6..e2a7119b 100644 --- a/lib/web/statusRouter.js +++ b/lib/web/statusRouter.js @@ -23,73 +23,6 @@ statusRouter.get('/status', function (req, res, next) { res.send(data) }) }) -// get status -statusRouter.get('/temp', function (req, res) { - var host = req.get('host') - if (config.allowOrigin.indexOf(host) === -1) { - response.errorForbidden(res) - } else { - var tempid = req.query.tempid - if (!tempid) { - response.errorForbidden(res) - } else { - models.Temp.findOne({ - where: { - id: tempid - } - }).then(function (temp) { - if (!temp) { - response.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 response.errorInternalError(res) - }) - } - } -}) -// post status -statusRouter.post('/temp', urlencodedParser, function (req, res) { - var host = req.get('host') - if (config.allowOrigin.indexOf(host) === -1) { - response.errorForbidden(res) - } else { - var data = req.body.data - if (!data) { - response.errorForbidden(res) - } else { - if (config.debug) { - logger.info('SERVER received temp from [' + host + ']: ' + req.body.data) - } - models.Temp.create({ - data: data - }).then(function (temp) { - if (temp) { - res.header('Access-Control-Allow-Origin', '*') - res.send({ - status: 'ok', - id: temp.id - }) - } else { - response.errorInternalError(res) - } - }).catch(function (err) { - logger.error(err) - return response.errorInternalError(res) - }) - } - } -}) statusRouter.get('/config', function (req, res) { var data = { diff --git a/public/js/history.js b/public/js/history.js index d1c7f25f..da39f095 100644 --- a/public/js/history.js +++ b/public/js/history.js @@ -6,8 +6,6 @@ import LZString from '@hackmd/lz-string' import escapeHTML from 'lodash/escape' -import wurl from 'wurl' - import { checkNoteIdValid, encodeNoteId @@ -19,38 +17,6 @@ import { urlpath } from './lib/config' window.migrateHistoryFromTempCallback = null -migrateHistoryFromTemp() - -function migrateHistoryFromTemp () { - if (wurl('#tempid')) { - $.get(`${serverurl}/temp`, { - tempid: wurl('#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( () => {