style: apply prettier fixes
This commit is contained in:
parent
a5e1e38e74
commit
80a2b34d43
8 changed files with 24 additions and 21 deletions
|
@ -190,7 +190,7 @@ app.post(
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'User-Agent': 'Actual Budget'
|
'User-Agent': 'Actual Budget'
|
||||||
}
|
}
|
||||||
}).then(res => res.json());
|
}).then((res) => res.json());
|
||||||
|
|
||||||
await req.runQuery(
|
await req.runQuery(
|
||||||
'INSERT INTO access_tokens (item_id, user_id, access_token) VALUES ($1, $2, $3)',
|
'INSERT INTO access_tokens (item_id, user_id, access_token) VALUES ($1, $2, $3)',
|
||||||
|
@ -233,7 +233,7 @@ app.post(
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'User-Agent': 'Actual Budget'
|
'User-Agent': 'Actual Budget'
|
||||||
}
|
}
|
||||||
}).then(res => res.json());
|
}).then((res) => res.json());
|
||||||
|
|
||||||
if (resData.removed !== true) {
|
if (resData.removed !== true) {
|
||||||
console.log('[Error] Item not removed: ' + access_token.slice(0, 3));
|
console.log('[Error] Item not removed: ' + access_token.slice(0, 3));
|
||||||
|
@ -286,7 +286,7 @@ app.post(
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'User-Agent': 'Actual Budget'
|
'User-Agent': 'Actual Budget'
|
||||||
}
|
}
|
||||||
}).then(res => res.json());
|
}).then((res) => res.json());
|
||||||
|
|
||||||
res.send(
|
res.send(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
|
@ -342,7 +342,7 @@ app.post(
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'User-Agent': 'Actual Budget'
|
'User-Agent': 'Actual Budget'
|
||||||
}
|
}
|
||||||
}).then(res => res.json());
|
}).then((res) => res.json());
|
||||||
|
|
||||||
res.send(
|
res.send(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
|
|
|
@ -136,7 +136,7 @@ app.post('/sync', async (req, res) => {
|
||||||
let responsePb = new SyncPb.SyncResponse();
|
let responsePb = new SyncPb.SyncResponse();
|
||||||
responsePb.setMerkle(JSON.stringify(trie));
|
responsePb.setMerkle(JSON.stringify(trie));
|
||||||
|
|
||||||
newMessages.forEach(msg => responsePb.addMessages(msg));
|
newMessages.forEach((msg) => responsePb.addMessages(msg));
|
||||||
|
|
||||||
res.set('Content-Type', 'application/actual-sync');
|
res.set('Content-Type', 'application/actual-sync');
|
||||||
res.send(Buffer.from(responsePb.serializeBinary()));
|
res.send(Buffer.from(responsePb.serializeBinary()));
|
||||||
|
@ -376,7 +376,7 @@ app.get('/list-user-files', (req, res) => {
|
||||||
res.send(
|
res.send(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
status: 'ok',
|
status: 'ok',
|
||||||
data: rows.map(row => ({
|
data: rows.map((row) => ({
|
||||||
deleted: row.deleted,
|
deleted: row.deleted,
|
||||||
fileId: row.id,
|
fileId: row.id,
|
||||||
groupId: row.group_id,
|
groupId: row.group_id,
|
||||||
|
|
4
app.js
4
app.js
|
@ -10,7 +10,7 @@ const syncApp = require('./app-sync');
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
process.on('unhandledRejection', reason => {
|
process.on('unhandledRejection', (reason) => {
|
||||||
console.log('Rejection:', reason);
|
console.log('Rejection:', reason);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ async function run() {
|
||||||
app.listen(config.port, config.hostname);
|
app.listen(config.port, config.hostname);
|
||||||
}
|
}
|
||||||
|
|
||||||
run().catch(err => {
|
run().catch((err) => {
|
||||||
console.log('Error starting app:', err);
|
console.log('Error starting app:', err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|
|
@ -37,7 +37,7 @@ CREATE TABLE kvcache_key (id INTEGER PRIMARY KEY, key REAL);
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
db.transaction(() => {
|
db.transaction(() => {
|
||||||
budget.map(monthBudget => {
|
budget.map((monthBudget) => {
|
||||||
let match = monthBudget.name.match(
|
let match = monthBudget.name.match(
|
||||||
/^(budget-report|budget)(\d+)!budget-(.+)$/
|
/^(budget-report|budget)(\d+)!budget-(.+)$/
|
||||||
);
|
);
|
||||||
|
@ -84,7 +84,7 @@ CREATE TABLE kvcache_key (id INTEGER PRIMARY KEY, key REAL);
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
db.transaction(() => {
|
db.transaction(() => {
|
||||||
buffers.map(buffer => {
|
buffers.map((buffer) => {
|
||||||
let match = buffer.name.match(/^budget(\d+)!buffered$/);
|
let match = buffer.name.match(/^budget(\d+)!buffered$/);
|
||||||
if (match) {
|
if (match) {
|
||||||
let month = match[1].slice(0, 4) + '-' + match[1].slice(4);
|
let month = match[1].slice(0, 4) + '-' + match[1].slice(4);
|
||||||
|
@ -108,7 +108,7 @@ CREATE TABLE kvcache_key (id INTEGER PRIMARY KEY, key REAL);
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
let parseNote = str => {
|
let parseNote = (str) => {
|
||||||
try {
|
try {
|
||||||
let value = JSON.parse(str);
|
let value = JSON.parse(str);
|
||||||
return value && value !== '' ? value : null;
|
return value && value !== '' ? value : null;
|
||||||
|
@ -118,7 +118,7 @@ CREATE TABLE kvcache_key (id INTEGER PRIMARY KEY, key REAL);
|
||||||
};
|
};
|
||||||
|
|
||||||
db.transaction(() => {
|
db.transaction(() => {
|
||||||
notes.forEach(note => {
|
notes.forEach((note) => {
|
||||||
let parsed = parseNote(getValue(note));
|
let parsed = parseNote(getValue(note));
|
||||||
if (parsed) {
|
if (parsed) {
|
||||||
let [, id] = note.name.split('!');
|
let [, id] = note.name.split('!');
|
||||||
|
|
|
@ -15,7 +15,7 @@ const sync = sequential(async function syncAPI(messages, since, fileId) {
|
||||||
await actual.internal.send('load-budget', { id: fileId });
|
await actual.internal.send('load-budget', { id: fileId });
|
||||||
}
|
}
|
||||||
|
|
||||||
messages = messages.map(envPb => {
|
messages = messages.map((envPb) => {
|
||||||
let timestamp = envPb.getTimestamp();
|
let timestamp = envPb.getTimestamp();
|
||||||
let msg = SyncPb.Message.deserializeBinary(envPb.getContent());
|
let msg = SyncPb.Message.deserializeBinary(envPb.getContent());
|
||||||
return {
|
return {
|
||||||
|
@ -27,11 +27,14 @@ const sync = sequential(async function syncAPI(messages, since, fileId) {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
const newMessages = await actual.internal.syncAndReceiveMessages(messages, since);
|
const newMessages = await actual.internal.syncAndReceiveMessages(
|
||||||
|
messages,
|
||||||
|
since
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
trie: actual.internal.timestamp.getClock().merkle,
|
trie: actual.internal.timestamp.getClock().merkle,
|
||||||
newMessages: newMessages.map(msg => {
|
newMessages: newMessages.map((msg) => {
|
||||||
const envelopePb = new SyncPb.MessageEnvelope();
|
const envelopePb = new SyncPb.MessageEnvelope();
|
||||||
|
|
||||||
const messagePb = new SyncPb.Message();
|
const messagePb = new SyncPb.Message();
|
||||||
|
|
|
@ -74,7 +74,7 @@ function sync(messages, since, fileId) {
|
||||||
`SELECT * FROM messages_binary
|
`SELECT * FROM messages_binary
|
||||||
WHERE timestamp > ?
|
WHERE timestamp > ?
|
||||||
ORDER BY timestamp`,
|
ORDER BY timestamp`,
|
||||||
[since],
|
[since]
|
||||||
);
|
);
|
||||||
|
|
||||||
let trie = addMessages(db, messages);
|
let trie = addMessages(db, messages);
|
||||||
|
|
|
@ -17,11 +17,11 @@ function sequential(fn) {
|
||||||
sequenceState.running = fn(...args);
|
sequenceState.running = fn(...args);
|
||||||
|
|
||||||
sequenceState.running.then(
|
sequenceState.running.then(
|
||||||
val => {
|
(val) => {
|
||||||
pump();
|
pump();
|
||||||
resolve(val);
|
resolve(val);
|
||||||
},
|
},
|
||||||
err => {
|
(err) => {
|
||||||
pump();
|
pump();
|
||||||
reject(err);
|
reject(err);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
function handleError(func) {
|
function handleError(func) {
|
||||||
return (req, res) => {
|
return (req, res) => {
|
||||||
func(req, res).catch(err => {
|
func(req, res).catch((err) => {
|
||||||
console.log('Error', req.originalUrl, err);
|
console.log('Error', req.originalUrl, err);
|
||||||
res.status(500);
|
res.status(500);
|
||||||
res.send({ status: 'error', reason: 'internal-error' });
|
res.send({ status: 'error', reason: 'internal-error' });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { handleError }
|
module.exports = { handleError };
|
||||||
|
|
Loading…
Reference in a new issue