Skip to content
This repository was archived by the owner on Jun 3, 2020. It is now read-only.

Commit 0de1980

Browse files
committed
Add beaker.templates internal web api
1 parent d94d196 commit 0de1980

8 files changed

Lines changed: 52 additions & 44 deletions

File tree

crawler/util.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ exports.doCrawl = async function (archive, crawlSource, crawlDataset, crawlDatas
5454
}
5555

5656
const doCheckpoint = exports.doCheckpoint = async function (crawlDataset, crawlDatasetVersion, crawlSource, crawlSourceVersion) {
57-
5857
await db.run(`DELETE FROM crawl_sources_meta WHERE crawlDataset = ? AND crawlSourceId = ?`, [crawlDataset, crawlSource.id])
5958
await db.run(`
6059
INSERT

dbs/schemas/profile-data.sql.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@ CREATE TABLE watchlist (
100100
FOREIGN KEY (profileId) REFERENCES profiles (id) ON DELETE CASCADE
101101
);
102102
103+
-- list of the users current templates
104+
CREATE TABLE templates (
105+
profileId INTEGER,
106+
url TEXT NOT NULL,
107+
title TEXT,
108+
screenshot,
109+
createdAt INTEGER DEFAULT (strftime('%s', 'now')),
110+
111+
PRIMARY KEY (profileId, url),
112+
FOREIGN KEY (profileId) REFERENCES profiles (id) ON DELETE CASCADE
113+
);
114+
103115
-- list of sites being crawled
104116
CREATE TABLE crawl_sources (
105117
id INTEGER PRIMARY KEY NOT NULL,
@@ -157,19 +169,6 @@ CREATE TABLE crawl_followgraph (
157169
FOREIGN KEY (crawlSourceId) REFERENCES crawl_sources (id) ON DELETE CASCADE
158170
);
159171
160-
-- list of the users current templates
161-
-- deprecated (may return)
162-
CREATE TABLE templates (
163-
profileId INTEGER,
164-
url TEXT NOT NULL,
165-
title TEXT,
166-
screenshot,
167-
createdAt INTEGER DEFAULT (strftime('%s', 'now')),
168-
169-
PRIMARY KEY (profileId, url),
170-
FOREIGN KEY (profileId) REFERENCES profiles (id) ON DELETE CASCADE
171-
);
172-
173172
-- a list of the draft-dats for a master-dat
174173
-- deprecated
175174
CREATE TABLE archive_drafts (

web-apis/bg.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const downloadsManifest = require('./manifests/internal/downloads')
1010
const historyManifest = require('./manifests/internal/history')
1111
const sitedataManifest = require('./manifests/internal/sitedata')
1212
const watchlistManifest = require('./manifests/internal/watchlist')
13+
const templatesManifest = require('./manifests/internal/templates')
1314
const crawlerManifest = require('./manifests/internal/crawler')
1415
const postsManifest = require('./manifests/internal/posts')
1516
const followgraphManifest = require('./manifests/internal/followgraph')
@@ -20,6 +21,7 @@ const bookmarksAPI = require('./bg/bookmarks')
2021
const historyAPI = require('./bg/history')
2122
const sitedataAPI = require('../dbs/sitedata').WEBAPI
2223
const watchlistAPI = require('./bg/watchlist')
24+
const templatesAPI = require('./bg/templates')
2325
const crawlerAPI = require('../crawler').WEBAPI
2426
const postsAPI = require('./bg/posts')
2527
const followgraphAPI = require('./bg/followgraph')
@@ -56,6 +58,7 @@ exports.setup = function () {
5658
globals.rpcAPI.exportAPI('history', historyManifest, historyAPI, internalOnly)
5759
globals.rpcAPI.exportAPI('sitedata', sitedataManifest, sitedataAPI, internalOnly)
5860
globals.rpcAPI.exportAPI('watchlist', watchlistManifest, watchlistAPI, internalOnly)
61+
globals.rpcAPI.exportAPI('templates', templatesManifest, templatesAPI, internalOnly)
5962
globals.rpcAPI.exportAPI('crawler', crawlerManifest, crawlerAPI, internalOnly)
6063
globals.rpcAPI.exportAPI('posts', postsManifest, postsAPI, internalOnly)
6164
globals.rpcAPI.exportAPI('followgraph', followgraphManifest, followgraphAPI, internalOnly)

web-apis/bg/archives.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const path = require('path')
22
const mkdirp = require('mkdirp')
33
const jetpack = require('fs-jetpack')
4-
const templatesDb = require('../../dbs/templates')
54
const datDns = require('../../dat/dns')
65
const datLibrary = require('../../dat/library')
76
const datGC = require('../../dat/garbage-collector')
@@ -266,25 +265,6 @@ module.exports = {
266265
return archiveDraftsDb.remove(0, masterKey, draftKey)
267266
},
268267

269-
// templates
270-
// =
271-
272-
async getTemplate (url) {
273-
return templatesDb.get(0, url)
274-
},
275-
276-
async listTemplates () {
277-
return templatesDb.list(0)
278-
},
279-
280-
async putTemplate (url, {title, screenshot}) {
281-
return templatesDb.put(0, url, {title, screenshot})
282-
},
283-
284-
async removeTemplate (url) {
285-
return templatesDb.remove(0, url)
286-
},
287-
288268
// internal management
289269
// =
290270

web-apis/bg/templates.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const templatesDb = require('../../dbs/templates')
2+
3+
// exported api
4+
// =
5+
6+
module.exports = {
7+
async get (url) {
8+
return templatesDb.get(0, url)
9+
},
10+
11+
async list () {
12+
return templatesDb.list(0)
13+
},
14+
15+
async put (url, {title, screenshot}) {
16+
return templatesDb.put(0, url, {title, screenshot})
17+
},
18+
19+
async remove (url) {
20+
return templatesDb.remove(0, url)
21+
}
22+
}

web-apis/fg/beaker.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const downloadsManifest = require('../manifests/internal/downloads')
88
const historyManifest = require('../manifests/internal/history')
99
const sitedataManifest = require('../manifests/internal/sitedata')
1010
const watchlistManifest = require('../manifests/internal/watchlist')
11+
const templatesManifest = require('../manifests/internal/templates')
1112
const crawlerManifest = require('../manifests/internal/crawler')
1213
const postsManifest = require('../manifests/internal/posts')
1314
const followgraphManifest = require('../manifests/internal/followgraph')
@@ -25,6 +26,7 @@ exports.setup = function (rpc) {
2526
const historyRPC = rpc.importAPI('history', historyManifest, opts)
2627
const sitedataRPC = rpc.importAPI('sitedata', sitedataManifest, opts)
2728
const watchlistRPC = rpc.importAPI('watchlist', watchlistManifest, opts)
29+
const templatesRPC = rpc.importAPI('templates', templatesManifest, opts)
2830
const crawlerRPC = rpc.importAPI('crawler', crawlerManifest, opts)
2931
const postsRPC = rpc.importAPI('posts', postsManifest, opts)
3032
const followgraphRPC = rpc.importAPI('followgraph', followgraphManifest, opts)
@@ -49,10 +51,6 @@ exports.setup = function (rpc) {
4951
beaker.archives.listDrafts = archivesRPC.listDrafts
5052
beaker.archives.addDraft = archivesRPC.addDraft
5153
beaker.archives.removeDraft = archivesRPC.removeDraft
52-
beaker.archives.getTemplate = archivesRPC.getTemplate
53-
beaker.archives.listTemplates = archivesRPC.listTemplates
54-
beaker.archives.putTemplate = archivesRPC.putTemplate
55-
beaker.archives.removeTemplate = archivesRPC.removeTemplate
5654
beaker.archives.touch = archivesRPC.touch
5755
beaker.archives.clearFileCache = archivesRPC.clearFileCache
5856
beaker.archives.clearGarbage = archivesRPC.clearGarbage
@@ -160,6 +158,13 @@ exports.setup = function (rpc) {
160158
beaker.watchlist.remove = watchlistRPC.remove
161159
beaker.watchlist.createEventsStream = () => fromEventStream(watchlistRPC.createEventsStream())
162160

161+
// beaker.templates
162+
beaker.templates = {}
163+
beaker.templates.get = templatesRPC.get
164+
beaker.templates.list = templatesRPC.list
165+
beaker.templates.put = templatesRPC.put
166+
beaker.templates.remove = templatesRPC.remove
167+
163168
// beaker.crawler
164169
beaker.crawler = {}
165170
beaker.crawler.getCrawlStates = crawlerRPC.getCrawlStates

web-apis/manifests/internal/archives.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ module.exports = {
2727
addDraft: 'promise',
2828
removeDraft: 'promise',
2929

30-
// templates
31-
getTemplate: 'promise',
32-
listTemplates: 'promise',
33-
putTemplate: 'promise',
34-
removeTemplate: 'promise',
35-
3630
// internal management
3731
touch: 'promise',
3832
clearFileCache: 'promise',
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
get: 'promise',
3+
list: 'promise',
4+
put: 'promise',
5+
remove: 'promise'
6+
}

0 commit comments

Comments
 (0)