@@ -4,6 +4,7 @@ import { tsToDate } from "@webrecorder/wabac/src/utils.js";
4
4
import { Downloader } from "./downloader.js" ;
5
5
import { Signer } from "./keystore.js" ;
6
6
import { ipfsAdd , ipfsRemove , setAutoIPFSUrl } from "./ipfsutils.js" ;
7
+ import { RecProxy } from "./recproxy.js" ;
7
8
8
9
// eslint-disable-next-line no-undef
9
10
const DEFAULT_SOFTWARE_STRING = `Webrecorder ArchiveWeb.page ${ __AWP_VERSION__ } , using warcio.js ${ __WARCIO_VERSION__ } ` ;
@@ -20,6 +21,7 @@ class ExtAPI extends API
20
21
return {
21
22
...super . routes ,
22
23
"downloadPages" : "c/:coll/dl" ,
24
+ "recPending" : "c/:coll/recPending" ,
23
25
"pageTitle" : [ "c/:coll/pageTitle" , "POST" ] ,
24
26
"ipfsAdd" : [ "c/:coll/ipfs" , "POST" ] ,
25
27
"ipfsRemove" : [ "c/:coll/ipfs" , "DELETE" ] ,
@@ -38,21 +40,11 @@ class ExtAPI extends API
38
40
39
41
async handleApi ( request , params , event ) {
40
42
switch ( params . _route ) {
41
- case "downloadPages" : {
42
- const coll = await this . collections . loadColl ( params . coll ) ;
43
- if ( ! coll ) {
44
- return { error : "collection_not_found" } ;
45
- }
46
-
47
- const pageQ = params . _query . get ( "pages" ) ;
48
- const pageList = pageQ === "all" ? null : pageQ . split ( "," ) ;
49
-
50
- const format = params . _query . get ( "format" ) || "wacz" ;
51
- let filename = params . _query . get ( "filename" ) ;
43
+ case "downloadPages" :
44
+ return await this . handleDownload ( params ) ;
52
45
53
- const dl = new Downloader ( { ...this . downloaderOpts ( ) , coll, format, filename, pageList} ) ;
54
- return dl . download ( ) ;
55
- }
46
+ case "recPending" :
47
+ return await this . recordingPending ( params ) ;
56
48
57
49
case "pageTitle" :
58
50
return await this . updatePageTitle ( params . coll , request ) ;
@@ -66,11 +58,42 @@ class ExtAPI extends API
66
58
case "ipfsRemove" :
67
59
return await this . ipfsRemove ( request , params . coll ) ;
68
60
69
-
70
61
default :
71
62
return await super . handleApi ( request , params ) ;
72
63
}
73
64
}
65
+
66
+ async handleDownload ( params ) {
67
+ const coll = await this . collections . loadColl ( params . coll ) ;
68
+ if ( ! coll ) {
69
+ return { error : "collection_not_found" } ;
70
+ }
71
+
72
+ const pageQ = params . _query . get ( "pages" ) ;
73
+ const pageList = pageQ === "all" ? null : pageQ . split ( "," ) ;
74
+
75
+ const format = params . _query . get ( "format" ) || "wacz" ;
76
+ let filename = params . _query . get ( "filename" ) ;
77
+
78
+ const dl = new Downloader ( { ...this . downloaderOpts ( ) , coll, format, filename, pageList} ) ;
79
+ return dl . download ( ) ;
80
+ }
81
+
82
+ async recordingPending ( params ) {
83
+ const coll = await this . collections . loadColl ( params . coll ) ;
84
+ if ( ! coll ) {
85
+ return { error : "collection_not_found" } ;
86
+ }
87
+
88
+ if ( ! ( coll . store instanceof RecProxy ) ) {
89
+ return { error : "invalid_collection" } ;
90
+ }
91
+
92
+ const numPending = await coll . store . getCounter ( ) ;
93
+
94
+ return { numPending } ;
95
+ }
96
+
74
97
async prepareColl ( collId , request ) {
75
98
const coll = await this . collections . loadColl ( collId ) ;
76
99
if ( ! coll ) {
0 commit comments