Fix all dates
This commit is contained in:
parent
b376070ca6
commit
86e60cb25d
|
@ -99,6 +99,22 @@ class DB {
|
|||
}
|
||||
return rows;
|
||||
}
|
||||
async update(photo, fields) {
|
||||
if (fields.indexOf('updated') === -1) {
|
||||
fields.push('updated');
|
||||
photo.updated = Date.now();
|
||||
}
|
||||
const values = fields.map(el => photo[el]);
|
||||
const query = `UPDATE photos SET ${fields.map(el => { return el + ' = ?'; }).join(',')} WHERE id = ?;`;
|
||||
values.push(photo.id);
|
||||
try {
|
||||
await this.run(query, values);
|
||||
}
|
||||
catch (err) {
|
||||
this.log.error(`Error updating photo with columns: ${fields.join(', ')}`, err);
|
||||
this.log.info(query);
|
||||
}
|
||||
}
|
||||
async getBsky(random = false) {
|
||||
const order = random ? 'RANDOM()' : 'score ASC, created DESC';
|
||||
const query = `SELECT * FROM photos WHERE bsky = 0 ORDER BY ${order} LIMIT 1;`;
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,32 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
require("dotenv/config");
|
||||
const log_1 = require("./log");
|
||||
const db_1 = require("./db");
|
||||
async function fixDates() {
|
||||
const log = (0, log_1.createLog)('fixDates');
|
||||
const db = new db_1.DB();
|
||||
let rows;
|
||||
let parts;
|
||||
let d;
|
||||
try {
|
||||
rows = await db.getAll();
|
||||
}
|
||||
catch (err) {
|
||||
log.error(err);
|
||||
}
|
||||
for (let row of rows) {
|
||||
parts = row.name.split('_');
|
||||
d = new Date(parseInt(parts[0]), parseInt(parts[1]) - 1, parseInt(parts[2]));
|
||||
row.created = +d;
|
||||
try {
|
||||
await db.update(row, ['created']);
|
||||
log.info(`Updated row ${row.id}: created == ${row.created}`);
|
||||
}
|
||||
catch (err) {
|
||||
log.error('Error updating row', err);
|
||||
}
|
||||
}
|
||||
}
|
||||
fixDates();
|
||||
//# sourceMappingURL=fix.js.map
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"fix.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atLng {
|
|||
}
|
||||
|
||||
interface Photo {
|
||||
[key: string] : any;
|
||||
id : string;
|
||||
name : string;
|
||||
description : string;
|
||||
|
@ -131,6 +132,22 @@ export class DB {
|
|||
return rows;
|
||||
}
|
||||
|
||||
public async update (photo : Photo, fields : string[]) {
|
||||
if (fields.indexOf('updated') === -1) {
|
||||
fields.push('updated');
|
||||
photo.updated = Date.now();
|
||||
}
|
||||
const values : any[] = fields.map(el => photo[el]);
|
||||
const query : string = `UPDATE photos SET ${fields.map(el => { return el + ' = ?'}).join(',')} WHERE id = ?;`;
|
||||
values.push(photo.id);
|
||||
try {
|
||||
await this.run(query, values);
|
||||
} catch (err) {
|
||||
this.log.error(`Error updating photo with columns: ${fields.join(', ')}`, err);
|
||||
this.log.info(query);
|
||||
}
|
||||
}
|
||||
|
||||
public async getBsky (random : boolean = false) : Promise<Photo> {
|
||||
const order : string = random ? 'RANDOM()' : 'score ASC, created DESC';
|
||||
const query : string = `SELECT * FROM photos WHERE bsky = 0 ORDER BY ${order} LIMIT 1;`;
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
import 'dotenv/config';
|
||||
import { createLog } from './log';
|
||||
import type { Logger } from 'winston';
|
||||
import { DB } from './db';
|
||||
|
||||
async function fixDates () {
|
||||
const log : Logger = createLog('fixDates');
|
||||
const db : DB = new DB();
|
||||
let rows : any[];
|
||||
let parts : string[];
|
||||
let d : Date;
|
||||
|
||||
try {
|
||||
rows = await db.getAll();
|
||||
} catch (err) {
|
||||
log.error(err);
|
||||
}
|
||||
for (let row of rows) {
|
||||
parts = row.name.split('_')
|
||||
d = new Date(parseInt(parts[0]), parseInt(parts[1])-1, parseInt(parts[2]));
|
||||
row.created = + d;
|
||||
try {
|
||||
await db.update(row, ['created']);
|
||||
log.info(`Updated row ${row.id}: created == ${row.created}`);
|
||||
} catch (err) {
|
||||
log.error('Error updating row', err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fixDates();
|
Loading…
Reference in New Issue