-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
3,272 additions
and
3,118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
export { GeneralAgent, periodPresets } | ||
|
||
const paths = { | ||
SEARCH: '/api/search' | ||
} | ||
|
||
const REQUESTS = { | ||
CLIP_SEARCH: { | ||
path: paths.SEARCH, | ||
params: { | ||
TITLE: 'title', | ||
CREATED: 'created' | ||
} | ||
} | ||
} | ||
|
||
const periodPresets = ['TODAY', 'LAST_7_DAYS', 'LAST_30_DAYS', 'LAST_365_DAYS'] | ||
|
||
class GeneralAgent { | ||
/** | ||
* Create an agent. | ||
* | ||
* @param {string} host - Address to the Quantel server to query | ||
*/ | ||
|
||
constructor(host) { | ||
this.host = host | ||
} | ||
|
||
/** | ||
* Search for clips matching the given criteria. | ||
* | ||
* Special note on the created criteria: use one of the exported `periodPresets` | ||
* | ||
* @param {object} criteria - query criteria | ||
* @param {string} criteria.title - clip title criteria. * is allowed as a wildcard | ||
* @param {string} criteria.created - scope the search to clips created in a specific period | ||
* | ||
* @returns {Promise} - a promise containing the search results | ||
*/ | ||
|
||
searchClip(criteria) { | ||
const { path, params } = REQUESTS.CLIP_SEARCH | ||
|
||
const url = new URL(this.host) | ||
url.pathname = url.pathname + path | ||
url.searchParams.append(params.TITLE, criteria?.title) | ||
url.searchParams.append(params.CREATED, criteria?.created) | ||
|
||
return fetch(url.href).then((response) => { | ||
if (response.ok) { | ||
return response.json() | ||
} else | ||
throw new Error( | ||
`Unable to fetch results: ${response.status} - ${response.statusText}` | ||
) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { QuantelAgent } from './quantel/quantel-agent.js' | ||
|
||
function createSearchAgent(env) { | ||
return new QuantelAgent() | ||
} | ||
|
||
export { createSearchAgent } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.