hedgeagent/1.12.0 #1
19
lib/migrations/20260622225700-remove-temp.js
Normal file
19
lib/migrations/20260622225700-remove-temp.js
Normal file
@@ -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
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
|
||||||
}
|
|
||||||
@@ -5,10 +5,6 @@ const Router = require('express').Router
|
|||||||
const errors = require('../errors')
|
const errors = require('../errors')
|
||||||
const realtime = require('../realtime')
|
const realtime = require('../realtime')
|
||||||
const config = require('../config')
|
const config = require('../config')
|
||||||
const models = require('../models')
|
|
||||||
const logger = require('../logger')
|
|
||||||
|
|
||||||
const { urlencodedParser } = require('./utils')
|
|
||||||
|
|
||||||
const statusRouter = module.exports = Router()
|
const statusRouter = module.exports = Router()
|
||||||
|
|
||||||
@@ -36,71 +32,6 @@ statusRouter.get('/status', function (req, res, next) {
|
|||||||
res.send(data)
|
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) {
|
statusRouter.get('/config', function (req, res) {
|
||||||
const data = {
|
const data = {
|
||||||
|
|||||||
@@ -61,7 +61,6 @@ const options = {
|
|||||||
}
|
}
|
||||||
const historyList = new List('history', options)
|
const historyList = new List('history', options)
|
||||||
|
|
||||||
window.migrateHistoryFromTempCallback = pageInit
|
|
||||||
setloginStateChangeEvent(pageInit)
|
setloginStateChangeEvent(pageInit)
|
||||||
|
|
||||||
pageInit()
|
pageInit()
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
import store from 'store'
|
import store from 'store'
|
||||||
import LZString from 'lz-string'
|
import LZString from 'lz-string'
|
||||||
import url from 'wurl'
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
checkNoteIdValid,
|
checkNoteIdValid,
|
||||||
@@ -19,40 +18,6 @@ import {
|
|||||||
urlpath
|
urlpath
|
||||||
} from './lib/config'
|
} 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) {
|
export function saveHistory (notehistory) {
|
||||||
checkIfAuth(
|
checkIfAuth(
|
||||||
() => {
|
() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user