mirror of
https://github.com/bellingcat/auto-archiver-extension.git
synced 2026-06-08 03:28:34 +03:00
filter by archive date
This commit is contained in:
@@ -40,7 +40,7 @@ function processMessages(request, sender) {
|
||||
break;
|
||||
}
|
||||
case 'search': {
|
||||
search(resolve, reject, request.query);
|
||||
search(resolve, reject, request.query, request.archivedAfter, request.archivedBefore);
|
||||
break;
|
||||
}
|
||||
case 'status': {
|
||||
@@ -215,14 +215,21 @@ function checkTaskStatus(resolve, reject, task) {
|
||||
});
|
||||
}
|
||||
|
||||
function search(resolve, reject, url) {
|
||||
function search(resolve, reject, url, archivedAfter, archivedBefore) {
|
||||
console.log('API: SEARCH');
|
||||
chrome.identity.getAuthToken({ interactive: false }, async accessToken => {
|
||||
if (accessToken == undefined) {
|
||||
reject(new Error(LOGIN_FAILED));
|
||||
return;
|
||||
}
|
||||
fetch(`${API_ENDPOINT_TASKS}/search-url?` + new URLSearchParams({ url }), {
|
||||
let searchParams = { url };
|
||||
// convert date strings to python-readable or exclude if not set
|
||||
archivedAfter = dateStrToIso(archivedAfter);
|
||||
archivedBefore = dateStrToIso(archivedBefore);
|
||||
if (archivedAfter) { searchParams = { ...searchParams, archived_after: archivedAfter } }
|
||||
if (archivedBefore) { searchParams = { ...searchParams, archived_before: archivedBefore } }
|
||||
|
||||
fetch(`${API_ENDPOINT_TASKS}/search-url?` + new URLSearchParams(searchParams), {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -235,6 +242,16 @@ function search(resolve, reject, url) {
|
||||
});
|
||||
}
|
||||
|
||||
function dateStrToIso(dateStr) {
|
||||
if (dateStr) {
|
||||
const date = new Date(dateStr);
|
||||
if (!isNaN(date)) {
|
||||
return date.toISOString();
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
async function syncLocalTasks(resolve, reject) {
|
||||
console.log('API: SYNC');
|
||||
chrome.identity.getAuthToken({ interactive: false }, async accessToken => {
|
||||
|
||||
@@ -59,6 +59,14 @@
|
||||
</button>
|
||||
|
||||
</h5>
|
||||
<div class="row">
|
||||
<div class=" col s6">
|
||||
Archived after <input type="date" name="archived-after" v-model="archivedAfter" v-on:input="searchTasks" min="2020-01-01" />
|
||||
</div>
|
||||
<div class=" col s6">
|
||||
Archived before <input type="date" name="archived-before" v-model="archivedBefore" v-on:input="searchTasks" min="2020-01-01" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="input-field col s6">
|
||||
<i class="material-icons prefix">search</i>
|
||||
<input id="icon_prefix" type="text" ref="search" v-model="search" v-on:input="searchTasks">
|
||||
@@ -70,7 +78,7 @@
|
||||
<th class="col s1"></th>
|
||||
<th class="col s5">URL</th>
|
||||
<th class="col s2">Result</th>
|
||||
<th class="col s3">Date</th>
|
||||
<th class="col s3">Archive date</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -113,6 +121,8 @@ export default {
|
||||
isSearchingOnline: false,
|
||||
search: '',
|
||||
errorMessage: '',
|
||||
archivedAfter: '',
|
||||
archivedBefore: '',
|
||||
_public: true,
|
||||
tagsChips: null,
|
||||
groupVisibility: "-1",
|
||||
@@ -237,7 +247,7 @@ export default {
|
||||
(async () => {
|
||||
this.isSearchingOnline = true;
|
||||
try {
|
||||
const onlineTasks = await this.callBackground({ action: "search", query: this.search });
|
||||
const onlineTasks = await this.callBackground({ action: "search", query: this.search, archivedAfter: this.archivedAfter, archivedBefore: this.archivedBefore });
|
||||
if (!onlineTasks) return;
|
||||
this.onlineTasks = (onlineTasks || []).filter(task => !Object.keys(this.tasks).includes(task.id))
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user