clean up lint issues
[websub-hub] / src / db / sqlite / index.js
index 3fae300eec6b1d02a746f32aae1b3d978bf35fda..a30c9b4ff00c673902708c3011e2d88dbc874f4d 100644 (file)
@@ -20,7 +20,7 @@ const schemaVersionsSupported = {
   max: {
     major: 1,
     minor: 0,
-    patch: 2,
+    patch: 4,
   },
 };
 
@@ -302,7 +302,7 @@ class DatabaseSQLite extends Database {
         throw new DBErrors.UnexpectedResult('did not upsert authentication');
       }
     } catch (e) {
-      this.logger.error(_scope, 'failed', { error: e, identifier, scrubbedCredential })
+      this.logger.error(_scope, 'failed', { error: e, identifier, scrubbedCredential });
       throw e;
     }
   }
@@ -558,7 +558,7 @@ class DatabaseSQLite extends Database {
       httpRemoteAddr: null,
       httpFrom: null,
       ...data,
-    }
+    };
     this._subscriptionUpsertDataValidate(subscriptionData);
 
     let result;
@@ -759,7 +759,7 @@ class DatabaseSQLite extends Database {
   }
 
 
-  topicGetByUrl(dbCtx, topicUrl) {
+  topicGetByUrl(dbCtx, topicUrl, applyDefaults = true) {
     const _scope = _fileScope('topicGetByUrl');
     this.logger.debug(_scope, 'called', { topicUrl });
 
@@ -767,7 +767,10 @@ class DatabaseSQLite extends Database {
     try {
       topic = this.statement.topicGetByUrl.get({ topicUrl });
       DatabaseSQLite._topicDataToNative(topic);
-      return this._topicDefaults(topic);
+      if (applyDefaults) {
+        topic = this._topicDefaults(topic);
+      }
+      return topic;
     } catch (e) {
       this.logger.error(_scope, 'failed', { error: e, topic, topicUrl });
       throw e;
@@ -822,6 +825,19 @@ class DatabaseSQLite extends Database {
   }
 
 
+  topicPublishHistory(dbCtx, topicId, days) {
+    const _scope = _fileScope('topicPublishHistory');
+    this.logger.debug(_scope, 'called', { topicId, days });
+
+    const events = this.statement.topicPublishHistory.all({ topicId, daysAgo: days });
+    const history = Array.from({ length: days }, () => 0);
+    // eslint-disable-next-line security/detect-object-injection
+    events.forEach(({ daysAgo, contentUpdates }) => history[daysAgo] = Number(contentUpdates));
+
+    return history;
+  }
+
+
   topicSet(dbCtx, data) {
     const _scope = _fileScope('topicSet');
     this.logger.debug(_scope, 'called', data);
@@ -853,6 +869,8 @@ class DatabaseSQLite extends Database {
     const _scope = _fileScope('topicSetContent');
     const topicSetContentData = {
       contentType: null,
+      httpETag: null,
+      httpLastModified: null,
       ...data,
     };
     const logData = {
@@ -869,6 +887,14 @@ class DatabaseSQLite extends Database {
       if (result.changes !=  1) {
         throw new DBErrors.UnexpectedResult('did not set topic content');
       }
+      result = this.statement.topicSetContentHistory.run({
+        topicId: data.topicId,
+        contentHash: data.contentHash,
+        contentSize: data.content.length,
+      });
+      if (result.changes != 1) {
+        throw new DBErrors.UnexpectedResult('did not set topic content history');
+      }
       return this._engineInfo(result);
     } catch (e) {
       this.logger.error(_scope, 'failed', { error: e, ...logData });