Browse Source

URL harvester: format timestamps as local date format

master
vampirefrog 1 year ago
parent
commit
32685dfa8c
  1. 12
      index.js
  2. 2
      static/urls.html
  3. 7
      static/urls.js

12
index.js

@ -241,6 +241,7 @@ app.get('/urls', (req, res, next) => { @@ -241,6 +241,7 @@ app.get('/urls', (req, res, next) => {
let q = `
SELECT
c.*,
datetime(c.timestamp, 'localtime') AS timestamp,
ur.url AS url,
u.platform AS user_platform,
u.username AS user_username,
@ -638,6 +639,15 @@ function handleUrls(client, user, chat) { @@ -638,6 +639,15 @@ function handleUrls(client, user, chat) {
console.log(`Harvested URL ${canonicalUrl} ${info.title}`, util.secondsToTime(info.duration));
serverWS.clients.forEach(function(client) {
var date = new Date();
var pad = function(num) { return ('00'+num).slice(-2) };
date =
date.getFullYear() + '-' +
pad(date.getMonth() + 1) + '-' +
pad(date.getDate()) + ' ' +
pad(date.getHours()) + ':' +
pad(date.getMinutes()) + ':' +
pad(date.getSeconds());
client.send(JSON.stringify({
type: 'url',
data: {
@ -653,7 +663,7 @@ function handleUrls(client, user, chat) { @@ -653,7 +663,7 @@ function handleUrls(client, user, chat) {
value: chat.value,
currency: chat.currency,
amount: chat.amount,
timestamp: new Date()
timestamp: date
}
}
}));

2
static/urls.html

@ -32,7 +32,7 @@ @@ -32,7 +32,7 @@
<span class="badge badge-primary" v-if="chat.donation">{{chat.donation}}</span>
<span class="badge badge-secondary" v-if="!chat.donation">Scrub</span>
<span class="badge badge-secondary">{{chat.user.platform}}</span>
<span class="badge badge-secondary">{{chat.timestamp}}</span>
<span class="badge badge-secondary">{{chat.timestamp|formatSQLDate}}</span>
</footer>
</blockquote>
<small></small>

7
static/urls.js

@ -4,7 +4,12 @@ var app = new Vue({ @@ -4,7 +4,12 @@ var app = new Vue({
urls: []
},
filters: {
secondsToTime: util.secondsToTime
secondsToTime: util.secondsToTime,
formatSQLDate: function(d) {
var t = d.split(/[- :]/);
var d = new Date(t[0], t[1]-1, t[2], t[3], t[4], t[5]);
return d.toLocaleString();
}
},
created: function () {
fetch('/urls')

Loading…
Cancel
Save