This repository has been archived by the owner on Apr 11, 2024. It is now read-only.
-
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.
feat: Update scripts to for Cloudflare Workers.
- Loading branch information
1 parent
684d311
commit ec52d0d
Showing
10 changed files
with
243 additions
and
252 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 |
---|---|---|
@@ -1,6 +1,4 @@ | ||
import "https://deno.land/x/[email protected]/load.ts"; | ||
|
||
import { AirtableError, AirtableResp, RecordData } from "./typings.d.ts"; | ||
import { AirtableError, AirtableResp, RecordData } from './typings.d.ts'; | ||
|
||
/** | ||
* Upload podcast record object to Airtable | ||
|
@@ -16,10 +14,10 @@ export const airtableUpload = async ( | |
record: RecordData | ||
): Promise<string> => { | ||
const options: RequestInit = { | ||
method: "POST", | ||
method: 'POST', | ||
headers: { | ||
Authorization: `Bearer ${Deno.env.get("AIRTABLE_API")}`, | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${AIRTABLE_API}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
records: [ | ||
|
@@ -34,7 +32,7 @@ export const airtableUpload = async ( | |
|
||
try { | ||
const response: Response = await fetch( | ||
`${Deno.env.get("AIRTABLE_BOOKMARKS_ENDPOINT")}/${table}`, | ||
`${AIRTABLE_BOOKMARKS_ENDPOINT}/${table}`, | ||
options | ||
); | ||
const results: AirtableResp | AirtableError = await response.json(); | ||
|
@@ -50,7 +48,7 @@ export const airtableUpload = async ( | |
const recordFields = (results as AirtableResp).records[0].fields; | ||
|
||
return ( | ||
(recordFields.title || recordFields.tweet || recordFields.content) ?? "" | ||
(recordFields.title || recordFields.tweet || recordFields.content) ?? '' | ||
); | ||
} catch (error) { | ||
throw new Error(`Uploading repos to Airtable: \n ${error}`); | ||
|
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
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 |
---|---|---|
@@ -1,12 +1,10 @@ | ||
import "https://deno.land/x/[email protected]/load.ts"; | ||
|
||
import { airtableUpload } from "./airtable-upload.ts"; | ||
import { airtableUpload } from './airtable-upload.ts'; | ||
|
||
import { | ||
BookmarkingResponse, | ||
TwitterData, | ||
TwitterResponse, | ||
} from "./typings.d.ts"; | ||
} from './typings.d.ts'; | ||
|
||
// Match unicode and convert to emoji code | ||
const emojiRange = new RegExp( | ||
|
@@ -66,7 +64,7 @@ const expandLinks = async (url: string): Promise<string> => { | |
|
||
if (!request.url) { | ||
console.error({ | ||
message: "Expand Links: unable to expand URL.", | ||
message: 'Expand Links: unable to expand URL.', | ||
status: request.status, | ||
}); | ||
|
||
|
@@ -93,7 +91,7 @@ const expandShortLink = async (str: string, regex: RegExp): Promise<string> => { | |
const promises: Promise<string>[] = []; | ||
const pattern = new RegExp(regex); | ||
|
||
// deno-lint-ignore no-unused-vars | ||
// eslint-disable-next-line no-unused-vars | ||
str.replace(pattern, (match, ...args) => { | ||
const promise = expandLinks(match); | ||
promises.push(promise); | ||
|
@@ -102,7 +100,7 @@ const expandShortLink = async (str: string, regex: RegExp): Promise<string> => { | |
}); | ||
|
||
const data = await Promise.all(promises); | ||
const replacer = () => data.shift() ?? ""; | ||
const replacer = () => data.shift() ?? ''; | ||
|
||
return str.replace(regex, replacer); | ||
} catch (error) { | ||
|
@@ -119,10 +117,10 @@ const expandShortLink = async (str: string, regex: RegExp): Promise<string> => { | |
*/ | ||
const cleanUrl = (url: string): string => { | ||
const updatedStr = url | ||
.replace(/(https\:\/\/([a-z]+\.)?twitter\.com\/)/g, "") | ||
.replace(/(https:\/\/([a-z]+\.)?twitter\.com\/)/g, '') | ||
.replace( | ||
/.*\/status\/([0-9]+)(.*)?/g, | ||
"https://api.twitter.com/2/tweets/$1" | ||
'https://api.twitter.com/2/tweets/$1' | ||
); | ||
|
||
return updatedStr; | ||
|
@@ -144,8 +142,8 @@ const getTweetDetails = async (url: string): Promise<TwitterData> => { | |
`${endpoint}?tweet.fields=created_at&user.fields=username&expansions=author_id`, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${Deno.env.get("TWITTER_KEY")}`, | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${TWITTER_KEY}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
} | ||
); | ||
|
@@ -182,13 +180,13 @@ export const bookmarkTweets = async ( | |
): Promise<BookmarkingResponse> => { | ||
try { | ||
const tweetData = await getTweetDetails(url); | ||
const airtableResp = await airtableUpload("Tweets", { | ||
const airtableResp = await airtableUpload('Tweets', { | ||
...tweetData, | ||
tags, | ||
}); | ||
|
||
return { success: true, message: airtableResp, source: "bookmarkTweets" }; | ||
return { success: true, message: airtableResp, source: 'bookmarkTweets' }; | ||
} catch (error) { | ||
return { success: false, message: error, source: "bookmarkTweets" }; | ||
return { success: false, message: error, source: 'bookmarkTweets' }; | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,12 +1,10 @@ | ||
import "https://deno.land/x/[email protected]/load.ts"; | ||
|
||
import { airtableUpload } from "./airtable-upload.ts"; | ||
import { airtableUpload } from './airtable-upload.ts'; | ||
|
||
import { | ||
BookmarkData, | ||
BookmarkingResponse, | ||
VimeoResponse, | ||
} from "./typings.d.ts"; | ||
} from './typings.d.ts'; | ||
|
||
/** | ||
* Convert video url to API ready endpoint. Extracts video ID. | ||
|
@@ -18,7 +16,7 @@ import { | |
const cleanUrl = (url: string): string => { | ||
const updatedStr = url.replace( | ||
/(https:\/\/vimeo\.com\/)(.*)/g, | ||
"https://api.vimeo.com/videos/$2" | ||
'https://api.vimeo.com/videos/$2' | ||
); | ||
|
||
return updatedStr; | ||
|
@@ -38,7 +36,7 @@ const getVimeoDetails = async (url: string): Promise<BookmarkData> => { | |
const endpoint = cleanUrl(url); | ||
const request = await fetch(endpoint, { | ||
headers: { | ||
Authorization: `Bearer ${Deno.env.get("VIMEO_KEY")}`, | ||
Authorization: `Bearer ${VIMEO_KEY}`, | ||
}, | ||
}); | ||
const response: VimeoResponse = await request.json(); | ||
|
@@ -68,13 +66,13 @@ export const bookmarkVimeo = async ( | |
): Promise<BookmarkingResponse> => { | ||
try { | ||
const vimeoData = await getVimeoDetails(url); | ||
const airtableResp = await airtableUpload("Videos", { | ||
const airtableResp = await airtableUpload('Videos', { | ||
...vimeoData, | ||
tags, | ||
}); | ||
|
||
return { success: true, message: airtableResp, source: "bookmarkVimeo" }; | ||
return { success: true, message: airtableResp, source: 'bookmarkVimeo' }; | ||
} catch (error) { | ||
return { success: false, message: error, source: "bookmarkVimeo" }; | ||
return { success: false, message: error, source: 'bookmarkVimeo' }; | ||
} | ||
}; |
Oops, something went wrong.