nomagick commited on
Commit
2da1b7f
·
unverified ·
1 Parent(s): fdd8a8a
backend/functions/src/cloud-functions/crawler.ts CHANGED
@@ -121,8 +121,10 @@ ${this.content}
121
  return sseStream;
122
  }
123
 
 
124
  if (!ctx.req.accepts('text/plain') && (ctx.req.accepts('text/json') || ctx.req.accepts('application/json'))) {
125
  for await (const scrapped of this.puppeteerControl.scrap(urlToCrawl.toString(), noCache)) {
 
126
  if (!scrapped?.parsed?.content) {
127
  continue;
128
  }
@@ -131,9 +133,12 @@ ${this.content}
131
 
132
  return formatted;
133
  }
 
 
134
  }
135
 
136
  for await (const scrapped of this.puppeteerControl.scrap(urlToCrawl.toString(), noCache)) {
 
137
  if (!scrapped?.parsed?.content) {
138
  continue;
139
  }
@@ -143,7 +148,7 @@ ${this.content}
143
  return assignTransferProtocolMeta(`${formatted}`, { contentType: 'text/plain', envelope: null });
144
  }
145
 
146
- throw new Error('Unreachable');
147
  }
148
 
149
 
 
121
  return sseStream;
122
  }
123
 
124
+ let lastScrapped;
125
  if (!ctx.req.accepts('text/plain') && (ctx.req.accepts('text/json') || ctx.req.accepts('application/json'))) {
126
  for await (const scrapped of this.puppeteerControl.scrap(urlToCrawl.toString(), noCache)) {
127
+ lastScrapped = scrapped;
128
  if (!scrapped?.parsed?.content) {
129
  continue;
130
  }
 
133
 
134
  return formatted;
135
  }
136
+
137
+ return this.formatSnapshot(lastScrapped);
138
  }
139
 
140
  for await (const scrapped of this.puppeteerControl.scrap(urlToCrawl.toString(), noCache)) {
141
+ lastScrapped = scrapped;
142
  if (!scrapped?.parsed?.content) {
143
  continue;
144
  }
 
148
  return assignTransferProtocolMeta(`${formatted}`, { contentType: 'text/plain', envelope: null });
149
  }
150
 
151
+ return this.formatSnapshot(lastScrapped);
152
  }
153
 
154