[core] Update Deno Modules (#100)

This commit updates all used Deno modules to their latest version.

Since some of the used modules / functions were deprecated we had to
adjust our encrypt / descrypt functions and the generation of the source
and item ids, where we have to use a new md5 function.
This commit is contained in:
Rico Berger
2023-12-12 20:32:44 +01:00
committed by GitHub
parent 8065e19c85
commit 982add8fbb
18 changed files with 189 additions and 164 deletions

View File

@@ -1,13 +1,11 @@
import { SupabaseClient } from '@supabase/supabase-js';
import { Md5 } from 'std/md5';
import { Redis } from 'redis';
import { ISource } from '../models/source.ts';
import { IItem } from '../models/item.ts';
import { IProfile } from '../models/profile.ts';
import { decrypt } from '../utils/encrypt.ts';
import { fetchWithTimeout } from '../utils/fetchWithTimeout.ts';
import { uploadSourceIcon } from './utils/uploadFile.ts';
import { utils } from '../utils/index.ts';
import { feedutils } from './utils/index.ts';
export const getGithubFeed = async (
supabaseClient: SupabaseClient,
@@ -22,7 +20,7 @@ export const getGithubFeed = async (
if (!profile.accountGithub?.token) {
throw new Error('GitHub token is missing');
}
const token = await decrypt(profile.accountGithub.token);
const token = await utils.decrypt(profile.accountGithub.token);
if (
source.options.github.type === 'notifications' ||
@@ -59,7 +57,7 @@ export const getGithubFeed = async (
`github-${source.userId}-${source.columnId}-${source.options.github.type}-${source.options.github.participating}`;
source.title = user.login;
source.icon = user.avatar_url;
source.icon = await uploadSourceIcon(supabaseClient, source);
source.icon = await feedutils.uploadSourceIcon(supabaseClient, source);
notifications.push(...tmpNotifications);
} else if (
source.options.github.type === 'repositorynotifications' &&
@@ -89,10 +87,10 @@ export const getGithubFeed = async (
tmpNotifications[0].repository?.owner?.avatar_url
) {
source.icon = tmpNotifications[0].repository.owner.avatar_url;
source.icon = await uploadSourceIcon(supabaseClient, source);
source.icon = await feedutils.uploadSourceIcon(supabaseClient, source);
} else {
source.icon = `https://github.com/${owner}.png`;
source.icon = await uploadSourceIcon(supabaseClient, source);
source.icon = await feedutils.uploadSourceIcon(supabaseClient, source);
}
notifications.push(...tmpNotifications);
} else {
@@ -169,7 +167,7 @@ export const getGithubFeed = async (
`github-${source.userId}-${source.columnId}-${source.options.github.type}-${source.options.github.user}`;
source.title = source.options.github.user;
source.icon = user.avatar_url;
source.icon = await uploadSourceIcon(supabaseClient, source);
source.icon = await feedutils.uploadSourceIcon(supabaseClient, source);
source.link = `https://github.com/${source.options.github.user}`;
events.push(...tmpEvents);
@@ -197,7 +195,7 @@ export const getGithubFeed = async (
`github-${source.userId}-${source.columnId}-${source.options.github.type}-${owner}-${repo}`;
source.title = `${owner}/${repo}`;
source.icon = user.avatar_url;
source.icon = await uploadSourceIcon(supabaseClient, source);
source.icon = await feedutils.uploadSourceIcon(supabaseClient, source);
source.link = `https://github.com/${owner}/${repo}`;
events.push(...tmpEvents);
@@ -227,7 +225,7 @@ export const getGithubFeed = async (
`github-${source.userId}-${source.columnId}-${source.options.github.type}-${source.options.github.organization}`;
source.title = source.options.github.organization;
source.icon = user.avatar_url;
source.icon = await uploadSourceIcon(supabaseClient, source);
source.icon = await feedutils.uploadSourceIcon(supabaseClient, source);
source.link = `https://github.com/${source.options.github.organization}`;
events.push(...tmpEvents);
@@ -261,7 +259,7 @@ export const getGithubFeed = async (
`github-${source.userId}-${source.columnId}-${source.options.github.type}-${source.options.github.organization}`;
source.title = source.options.github.organization;
source.icon = org.avatar_url;
source.icon = await uploadSourceIcon(supabaseClient, source);
source.icon = await feedutils.uploadSourceIcon(supabaseClient, source);
source.link = `https://github.com/${source.options.github.organization}`;
events.push(...tmpEvents);
@@ -329,9 +327,8 @@ export const getGithubFeed = async (
);
source.id =
`github-${source.userId}-${source.columnId}-${source.options.github.type}-${
new Md5().update(source.options.github.query).toString()
}`;
`github-${source.userId}-${source.columnId}-${source.options.github.type}-${await utils
.md5(source.options.github.query)}`;
source.type = 'github';
source.title = source.options.github.queryName || 'Search';
source.icon = undefined;
@@ -378,7 +375,7 @@ const request = async (
url: string,
options: { token: string; params?: Record<string, string> },
) => {
const res = await fetchWithTimeout(
const res = await utils.fetchWithTimeout(
`https://api.github.com${url}${
options.params ? `?${new URLSearchParams(options.params).toString()}` : ''
}`,

View File

@@ -1,6 +1,5 @@
import { SupabaseClient } from '@supabase/supabase-js';
import { parseFeed } from 'rss';
import { Md5 } from 'std/md5';
import { FeedEntry } from 'rss/types';
import { unescape } from 'lodash';
import { Redis } from 'redis';
@@ -83,7 +82,7 @@ export const getGooglenewsFeed = async (
* `stackoverflow` and set the title and link for the source.
*/
if (source.id === '') {
source.id = generateSourceId(
source.id = await generateSourceId(
source.userId,
source.columnId,
source.options.googlenews.url,
@@ -123,7 +122,7 @@ export const getGooglenewsFeed = async (
* Create the item object and add it to the `items` array.
*/
items.push({
id: generateItemId(source.id, entry.id),
id: await generateItemId(source.id, entry.id),
userId: source.userId,
columnId: source.columnId,
sourceId: source.id,
@@ -179,14 +178,12 @@ const skipEntry = (
* id and the link of the RSS feed. We use the MD5 algorithm for the link to
* generate the id.
*/
const generateSourceId = (
const generateSourceId = async (
userId: string,
columnId: string,
link: string,
): string => {
return `googlenews-${userId}-${columnId}-${
new Md5().update(link).toString()
}`;
): Promise<string> => {
return `googlenews-${userId}-${columnId}-${await utils.md5(link)}`;
};
/**
@@ -194,8 +191,11 @@ const generateSourceId = (
* identifier of the item. We use the MD5 algorithm for the identifier, which
* can be the link of the item or the id of the item.
*/
const generateItemId = (sourceId: string, identifier: string): string => {
return `${sourceId}-${new Md5().update(identifier).toString()}`;
const generateItemId = async (
sourceId: string,
identifier: string,
): Promise<string> => {
return `${sourceId}-${await utils.md5(identifier)}`;
};
/**

View File

@@ -1,6 +1,5 @@
import { SupabaseClient } from '@supabase/supabase-js';
import { parseFeed } from 'rss';
import { Md5 } from 'std/md5';
import { FeedEntry } from 'rss/types';
import { Redis } from 'redis';
import { unescape } from 'lodash';
@@ -169,7 +168,7 @@ export const getLemmyFeed = async (
* set the title and link for the source.
*/
if (source.id === '') {
source.id = generateSourceId(
source.id = await generateSourceId(
source.userId,
source.columnId,
source.options.lemmy,
@@ -197,7 +196,7 @@ export const getLemmyFeed = async (
* function. The id is a combination of the source id and the id of the
* entry.
*/
const itemId = generateItemId(source.id, entry.id);
const itemId = await generateItemId(source.id, entry.id);
/**
* Create the item object and add it to the `items` array.
@@ -257,12 +256,12 @@ const skipEntry = (
* id and the link of the RSS feed. We use the MD5 algorithm for the link to
* generate the id.
*/
const generateSourceId = (
const generateSourceId = async (
userId: string,
columnId: string,
link: string,
): string => {
return `lemmy-${userId}-${columnId}-${new Md5().update(link).toString()}`;
): Promise<string> => {
return `lemmy-${userId}-${columnId}-${await utils.md5(link)}`;
};
/**
@@ -270,8 +269,11 @@ const generateSourceId = (
* identifier of the item. We use the MD5 algorithm for the identifier, which
* can be the link of the item or the id of the item.
*/
const generateItemId = (sourceId: string, identifier: string): string => {
return `${sourceId}-${new Md5().update(identifier).toString()}`;
const generateItemId = async (
sourceId: string,
identifier: string,
): Promise<string> => {
return `${sourceId}-${await utils.md5(identifier)}`;
};
/**

View File

@@ -1,6 +1,5 @@
import { SupabaseClient } from '@supabase/supabase-js';
import { parseFeed } from 'rss';
import { Md5 } from 'std/md5';
import { FeedEntry } from 'rss/types';
import { Redis } from 'redis';
import { unescape } from 'lodash';
@@ -67,7 +66,7 @@ export const getMastodonFeed = async (
* user input as title.
*/
if (source.id === '') {
source.id = generateSourceId(
source.id = await generateSourceId(
source.userId,
source.columnId,
source.options.mastodon,
@@ -109,9 +108,9 @@ export const getMastodonFeed = async (
*/
let itemId = '';
if (entry.id != '') {
itemId = generateItemId(source.id, entry.id);
itemId = await generateItemId(source.id, entry.id);
} else if (entry.links.length > 0 && entry.links[0].href) {
itemId = generateItemId(source.id, entry.links[0].href);
itemId = await generateItemId(source.id, entry.links[0].href);
} else {
continue;
}
@@ -191,12 +190,12 @@ const skipEntry = (
* id and the link of the RSS feed. We use the MD5 algorithm for the link to
* generate the id.
*/
const generateSourceId = (
const generateSourceId = async (
userId: string,
columnId: string,
link: string,
): string => {
return `mastodon-${userId}-${columnId}-${new Md5().update(link).toString()}`;
): Promise<string> => {
return `mastodon-${userId}-${columnId}-${await utils.md5(link)}`;
};
/**
@@ -204,8 +203,11 @@ const generateSourceId = (
* identifier of the item. We use the MD5 algorithm for the identifier, which
* can be the link of the item or the id of the item.
*/
const generateItemId = (sourceId: string, identifier: string): string => {
return `${sourceId}-${new Md5().update(identifier).toString()}`;
const generateItemId = async (
sourceId: string,
identifier: string,
): Promise<string> => {
return `${sourceId}-${await utils.md5(identifier)}`;
};
/**

View File

@@ -1,6 +1,5 @@
import { SupabaseClient } from '@supabase/supabase-js';
import { parseFeed } from 'rss';
import { Md5 } from 'std/md5';
import { FeedEntry } from 'rss/types';
import { Redis } from 'redis';
import { unescape } from 'lodash';
@@ -112,7 +111,7 @@ export const getMediumFeed = async (
* the title and link for the source.
*/
if (source.id === '') {
source.id = generateSourceId(
source.id = await generateSourceId(
source.userId,
source.columnId,
parsedMediumOption,
@@ -144,9 +143,9 @@ export const getMediumFeed = async (
*/
let itemId = '';
if (entry.id != '') {
itemId = generateItemId(source.id, entry.id);
itemId = await generateItemId(source.id, entry.id);
} else if (entry.links.length > 0 && entry.links[0].href) {
itemId = generateItemId(source.id, entry.links[0].href);
itemId = await generateItemId(source.id, entry.links[0].href);
} else {
continue;
}
@@ -246,12 +245,12 @@ const skipEntry = (
* id and the link of the RSS feed. We use the MD5 algorithm for the link to
* generate the id.
*/
const generateSourceId = (
const generateSourceId = async (
userId: string,
columnId: string,
link: string,
): string => {
return `medium-${userId}-${columnId}-${new Md5().update(link).toString()}`;
): Promise<string> => {
return `medium-${userId}-${columnId}-${await utils.md5(link)}`;
};
/**
@@ -259,8 +258,11 @@ const generateSourceId = (
* identifier of the item. We use the MD5 algorithm for the identifier, which
* can be the link of the item or the id of the item.
*/
const generateItemId = (sourceId: string, identifier: string): string => {
return `${sourceId}-${new Md5().update(identifier).toString()}`;
const generateItemId = async (
sourceId: string,
identifier: string,
): Promise<string> => {
return `${sourceId}-${await utils.md5(identifier)}`;
};
/**

View File

@@ -1,6 +1,5 @@
import { SupabaseClient } from '@supabase/supabase-js';
import { parseFeed } from 'rss';
import { Md5 } from 'std/md5';
import { FeedEntry } from 'rss/types';
import { Redis } from 'redis';
import { unescape } from 'lodash';
@@ -61,7 +60,7 @@ export const getNitterFeed = async (
* user input as title.
*/
if (source.id === '') {
source.id = generateSourceId(
source.id = await generateSourceId(
source.userId,
source.columnId,
source.options.nitter,
@@ -101,9 +100,9 @@ export const getNitterFeed = async (
*/
let itemId = '';
if (entry.id != '') {
itemId = generateItemId(source.id, entry.id);
itemId = await generateItemId(source.id, entry.id);
} else if (entry.links.length > 0 && entry.links[0].href) {
itemId = generateItemId(source.id, entry.links[0].href);
itemId = await generateItemId(source.id, entry.links[0].href);
} else {
continue;
}
@@ -233,21 +232,23 @@ export const parseNitterOptions = (
* id and the link of the RSS feed. We use the MD5 algorithm for the link to
* generate the id.
*/
const generateSourceId = (
const generateSourceId = async (
userId: string,
columnId: string,
link: string,
): string => {
return `nitter-${userId}-${columnId}-${new Md5().update(link).toString()}`;
): Promise<string> => {
return `nitter-${userId}-${columnId}-${await utils.md5(link)}`;
};
/**
* `generateItemId` generates a unique item id based on the source id and the
* identifier of the item. We use the MD5 algorithm for the identifier, which
* can be the link of the item or the id of the item.
*/
const generateItemId = (sourceId: string, identifier: string): string => {
return `${sourceId}-${new Md5().update(identifier).toString()}`;
const generateItemId = async (
sourceId: string,
identifier: string,
): Promise<string> => {
return `${sourceId}-${await utils.md5(identifier)}`;
};
/**

View File

@@ -1,6 +1,5 @@
import { SupabaseClient } from '@supabase/supabase-js';
import { parseFeed } from 'rss';
import { Md5 } from 'std/md5';
import { FeedEntry } from 'rss/types';
import { Redis } from 'redis';
import { unescape } from 'lodash';
@@ -143,7 +142,7 @@ export const getPinterestFeed = async (
* set the title and link for the source.
*/
if (source.id === '') {
source.id = generateSourceId(
source.id = await generateSourceId(
source.userId,
source.columnId,
parsedPinterestOption,
@@ -175,9 +174,9 @@ export const getPinterestFeed = async (
*/
let itemId = '';
if (entry.id != '') {
itemId = generateItemId(source.id, entry.id);
itemId = await generateItemId(source.id, entry.id);
} else if (entry.links.length > 0 && entry.links[0].href) {
itemId = generateItemId(source.id, entry.links[0].href);
itemId = await generateItemId(source.id, entry.links[0].href);
} else {
continue;
}
@@ -256,12 +255,12 @@ const skipEntry = (
* id and the link of the RSS feed. We use the MD5 algorithm for the link to
* generate the id.
*/
const generateSourceId = (
const generateSourceId = async (
userId: string,
columnId: string,
link: string,
): string => {
return `pinterest-${userId}-${columnId}-${new Md5().update(link).toString()}`;
): Promise<string> => {
return `pinterest-${userId}-${columnId}-${await utils.md5(link)}`;
};
/**
@@ -269,8 +268,11 @@ const generateSourceId = (
* identifier of the item. We use the MD5 algorithm for the identifier, which
* can be the link of the item or the id of the item.
*/
const generateItemId = (sourceId: string, identifier: string): string => {
return `${sourceId}-${new Md5().update(identifier).toString()}`;
const generateItemId = async (
sourceId: string,
identifier: string,
): Promise<string> => {
return `${sourceId}-${await utils.md5(identifier)}`;
};
/**

View File

@@ -1,6 +1,5 @@
import { SupabaseClient } from '@supabase/supabase-js';
import { parseFeed } from 'rss';
import { Md5 } from 'std/md5';
import { FeedEntry } from 'rss/types';
import { Redis } from 'redis';
import { unescape } from 'lodash';
@@ -60,7 +59,7 @@ export const getPodcastFeed = async (
* CDN url.
*/
if (!source.id) {
source.id = generateSourceId(
source.id = await generateSourceId(
source.userId,
source.columnId,
source.options.podcast,
@@ -109,9 +108,9 @@ export const getPodcastFeed = async (
*/
let itemId = '';
if (entry.id != '') {
itemId = generateItemId(source.id, entry.id);
itemId = await generateItemId(source.id, entry.id);
} else if (entry.links && entry.links.length > 0 && entry.links[0].href) {
itemId = generateItemId(source.id, entry.links[0].href);
itemId = await generateItemId(source.id, entry.links[0].href);
} else {
continue;
}
@@ -194,12 +193,12 @@ const getRSSFeedFromApplePodcast = async (id: string): Promise<string> => {
* id and the link of the RSS feed. We use the MD5 algorithm for the link to
* generate the id.
*/
const generateSourceId = (
const generateSourceId = async (
userId: string,
columnId: string,
link: string,
): string => {
return `podcast-${userId}-${columnId}-${new Md5().update(link).toString()}`;
): Promise<string> => {
return `podcast-${userId}-${columnId}-${await utils.md5(link)}`;
};
/**
@@ -207,8 +206,11 @@ const generateSourceId = (
* identifier of the item. We use the MD5 algorithm for the identifier, which
* can be the link of the item or the id of the item.
*/
const generateItemId = (sourceId: string, identifier: string): string => {
return `${sourceId}-${new Md5().update(identifier).toString()}`;
const generateItemId = async (
sourceId: string,
identifier: string,
): Promise<string> => {
return `${sourceId}-${await utils.md5(identifier)}`;
};
/**

View File

@@ -1,6 +1,5 @@
import { SupabaseClient } from '@supabase/supabase-js';
import { parseFeed } from 'rss';
import { Md5 } from 'std/md5';
import { FeedEntry } from 'rss/types';
import { Redis } from 'redis';
import { unescape } from 'lodash';
@@ -66,7 +65,7 @@ export const getRedditFeed = async (
* set the title and link for the source.
*/
if (source.id === '') {
source.id = generateSourceId(
source.id = await generateSourceId(
source.userId,
source.columnId,
source.options.reddit,
@@ -97,9 +96,9 @@ export const getRedditFeed = async (
*/
let itemId = '';
if (entry.id != '') {
itemId = generateItemId(source.id, entry.id);
itemId = await generateItemId(source.id, entry.id);
} else if (entry.links.length > 0 && entry.links[0].href) {
itemId = generateItemId(source.id, entry.links[0].href);
itemId = await generateItemId(source.id, entry.links[0].href);
} else {
continue;
}
@@ -162,12 +161,12 @@ const skipEntry = (
* id and the link of the RSS feed. We use the MD5 algorithm for the link to
* generate the id.
*/
const generateSourceId = (
const generateSourceId = async (
userId: string,
columnId: string,
link: string,
): string => {
return `reddit-${userId}-${columnId}-${new Md5().update(link).toString()}`;
): Promise<string> => {
return `reddit-${userId}-${columnId}-${await utils.md5(link)}`;
};
/**
@@ -175,8 +174,11 @@ const generateSourceId = (
* identifier of the item. We use the MD5 algorithm for the identifier, which
* can be the link of the item or the id of the item.
*/
const generateItemId = (sourceId: string, identifier: string): string => {
return `${sourceId}-${new Md5().update(identifier).toString()}`;
const generateItemId = async (
sourceId: string,
identifier: string,
): Promise<string> => {
return `${sourceId}-${await utils.md5(identifier)}`;
};
/**

View File

@@ -1,6 +1,5 @@
import { SupabaseClient } from '@supabase/supabase-js';
import { Feed, parseFeed } from 'rss';
import { Md5 } from 'std/md5';
import { FeedEntry } from 'rss/types';
import { Redis } from 'redis';
import { unescape } from 'lodash';
@@ -55,7 +54,7 @@ export const getRSSFeed = async (
* of the source to `rss` and the title to the title of the feed.
*/
if (source.id === '') {
source.id = generateSourceId(
source.id = await generateSourceId(
source.userId,
source.columnId,
source.options.rss,
@@ -120,9 +119,9 @@ export const getRSSFeed = async (
*/
let itemId = '';
if (entry.id) {
itemId = generateItemId(source.id, entry.id);
itemId = await generateItemId(source.id, entry.id);
} else {
itemId = generateItemId(source.id, entry.links[0].href!);
itemId = await generateItemId(source.id, entry.links[0].href!);
}
/**
@@ -285,12 +284,12 @@ const getDCDateTimestamp = (dcdate: Date | { value: Date }): number => {
* id and the link of the RSS feed. We use the MD5 algorithm for the link to
* generate the id.
*/
const generateSourceId = (
const generateSourceId = async (
userId: string,
columnId: string,
link: string,
): string => {
return `rss-${userId}-${columnId}-${new Md5().update(link).toString()}`;
): Promise<string> => {
return `rss-${userId}-${columnId}-${await utils.md5(link)}`;
};
/**
@@ -298,8 +297,11 @@ const generateSourceId = (
* identifier of the item. We use the MD5 algorithm for the identifier, which
* can be the link of the item or the id of the item.
*/
const generateItemId = (sourceId: string, identifier: string): string => {
return `${sourceId}-${new Md5().update(identifier).toString()}`;
const generateItemId = async (
sourceId: string,
identifier: string,
): Promise<string> => {
return `${sourceId}-${await utils.md5(identifier)}`;
};
/**

View File

@@ -1,7 +1,6 @@
import { SupabaseClient } from '@supabase/supabase-js';
import { parseFeed } from 'rss';
import { FeedEntry } from 'rss/types';
import { Md5 } from 'std/md5';
import { Redis } from 'redis';
import { unescape } from 'lodash';
@@ -58,7 +57,7 @@ export const getStackoverflowFeed = async (
* `stackoverflow` and set the title and link for the source.
*/
if (source.id === '') {
source.id = generateSourceId(
source.id = await generateSourceId(
source.userId,
source.columnId,
source.options.stackoverflow.url,
@@ -86,7 +85,7 @@ export const getStackoverflowFeed = async (
* Create the item object and add it to the `items` array.
*/
items.push({
id: generateItemId(source.id, entry.id),
id: await generateItemId(source.id, entry.id),
userId: source.userId,
columnId: source.columnId,
sourceId: source.id,
@@ -142,14 +141,12 @@ const skipEntry = (
* id and the link of the RSS feed. We use the MD5 algorithm for the link to
* generate the id.
*/
const generateSourceId = (
const generateSourceId = async (
userId: string,
columnId: string,
link: string,
): string => {
return `stackoverflow-${userId}-${columnId}-${
new Md5().update(link).toString()
}`;
): Promise<string> => {
return `stackoverflow-${userId}-${columnId}-${await utils.md5(link)}`;
};
/**
@@ -157,6 +154,9 @@ const generateSourceId = (
* identifier of the item. We use the MD5 algorithm for the identifier, which
* can be the link of the item or the id of the item.
*/
const generateItemId = (sourceId: string, identifier: string): string => {
return `${sourceId}-${new Md5().update(identifier).toString()}`;
const generateItemId = async (
sourceId: string,
identifier: string,
): Promise<string> => {
return `${sourceId}-${await utils.md5(identifier)}`;
};

View File

@@ -1,6 +1,5 @@
import { SupabaseClient } from '@supabase/supabase-js';
import { parseFeed } from 'rss';
import { Md5 } from 'std/md5';
import { FeedEntry } from 'rss/types';
import { unescape } from 'lodash';
import { Redis } from 'redis';
@@ -70,7 +69,7 @@ export const getTumblrFeed = async (
* the title and link for the source.
*/
if (source.id === '') {
source.id = generateSourceId(
source.id = await generateSourceId(
source.userId,
source.columnId,
source.options.tumblr,
@@ -98,7 +97,7 @@ export const getTumblrFeed = async (
* Create the item object and add it to the `items` array.
*/
items.push({
id: generateItemId(source.id, entry.id),
id: await generateItemId(source.id, entry.id),
userId: source.userId,
columnId: source.columnId,
sourceId: source.id,
@@ -154,12 +153,12 @@ const skipEntry = (
* id and the link of the RSS feed. We use the MD5 algorithm for the link to
* generate the id.
*/
const generateSourceId = (
const generateSourceId = async (
userId: string,
columnId: string,
link: string,
): string => {
return `tumblr-${userId}-${columnId}-${new Md5().update(link).toString()}`;
): Promise<string> => {
return `tumblr-${userId}-${columnId}-${await utils.md5(link)}`;
};
/**
@@ -167,8 +166,11 @@ const generateSourceId = (
* identifier of the item. We use the MD5 algorithm for the identifier, which
* can be the link of the item or the id of the item.
*/
const generateItemId = (sourceId: string, identifier: string): string => {
return `${sourceId}-${new Md5().update(identifier).toString()}`;
const generateItemId = async (
sourceId: string,
identifier: string,
): Promise<string> => {
return `${sourceId}-${await utils.md5(identifier)}`;
};
/**

View File

@@ -1,13 +1,12 @@
import { SupabaseClient } from '@supabase/supabase-js';
import { Md5 } from 'std/md5';
import { Redis } from 'redis';
import { unescape } from 'lodash';
import { IItem } from '../models/item.ts';
import { ISource } from '../models/source.ts';
import { uploadSourceIcon } from './utils/uploadFile.ts';
import { feedutils } from './utils/index.ts';
import { IProfile } from '../models/profile.ts';
import { fetchWithTimeout } from '../utils/fetchWithTimeout.ts';
import { utils } from '../utils/index.ts';
export const getXFeed = async (
supabaseClient: SupabaseClient,
@@ -27,7 +26,7 @@ export const getXFeed = async (
* Get the feed for the provided X username, based on the content of the HTML
* returned for the syndication.twitter.com url.
*/
const response = await fetchWithTimeout(
const response = await utils.fetchWithTimeout(
generateFeedUrl(source.options.x),
{ method: 'get' },
5000,
@@ -50,7 +49,7 @@ export const getXFeed = async (
* user input as title.
*/
if (source.id === '') {
source.id = generateSourceId(
source.id = await generateSourceId(
source.userId,
source.columnId,
source.options.x,
@@ -73,7 +72,7 @@ export const getXFeed = async (
) {
source.icon = feed.props.pageProps.timeline.entries[0].content.tweet.user
.profile_image_url_https;
source.icon = await uploadSourceIcon(supabaseClient, source);
source.icon = await feedutils.uploadSourceIcon(supabaseClient, source);
}
/**
@@ -94,7 +93,7 @@ export const getXFeed = async (
const media = getMedia(entry);
items.push({
id: generateItemId(source.id, entry.content.tweet.id_str),
id: await generateItemId(source.id, entry.content.tweet.id_str),
userId: source.userId,
columnId: source.columnId,
sourceId: source.id,
@@ -128,12 +127,12 @@ const generateFeedUrl = (input: string): string => {
* id and the link of the RSS feed. We use the MD5 algorithm for the link to
* generate the id.
*/
const generateSourceId = (
const generateSourceId = async (
userId: string,
columnId: string,
link: string,
): string => {
return `x-${userId}-${columnId}-${new Md5().update(link).toString()}`;
): Promise<string> => {
return `x-${userId}-${columnId}-${await utils.md5(link)}`;
};
/**
@@ -141,8 +140,11 @@ const generateSourceId = (
* identifier of the item. We use the MD5 algorithm for the identifier, which
* can be the link of the item or the id of the item.
*/
const generateItemId = (sourceId: string, identifier: string): string => {
return `${sourceId}-${new Md5().update(identifier).toString()}`;
const generateItemId = async (
sourceId: string,
identifier: string,
): Promise<string> => {
return `${sourceId}-${await utils.md5(identifier)}`;
};
/**

View File

@@ -1,6 +1,5 @@
import { SupabaseClient } from '@supabase/supabase-js';
import { parseFeed } from 'rss';
import { Md5 } from 'std/md5';
import { FeedEntry } from 'rss/types';
import { Redis } from 'redis';
import { unescape } from 'lodash';
@@ -111,7 +110,7 @@ export const getYoutubeFeed = async (
* set the title and link for the source.
*/
if (source.id === '') {
source.id = generateSourceId(
source.id = await generateSourceId(
source.userId,
source.columnId,
source.options.youtube,
@@ -142,9 +141,9 @@ export const getYoutubeFeed = async (
*/
let itemId = '';
if (entry.id != '') {
itemId = generateItemId(source.id, entry.id);
itemId = await generateItemId(source.id, entry.id);
} else if (entry.links.length > 0 && entry.links[0].href) {
itemId = generateItemId(source.id, entry.links[0].href);
itemId = await generateItemId(source.id, entry.links[0].href);
} else {
continue;
}
@@ -209,12 +208,12 @@ const skipEntry = (
* id and the link of the RSS feed. We use the MD5 algorithm for the link to
* generate the id.
*/
const generateSourceId = (
const generateSourceId = async (
userId: string,
columnId: string,
link: string,
): string => {
return `youtube-${userId}-${columnId}-${new Md5().update(link).toString()}`;
): Promise<string> => {
return `youtube-${userId}-${columnId}-${await utils.md5(link)}`;
};
/**
@@ -222,8 +221,11 @@ const generateSourceId = (
* identifier of the item. We use the MD5 algorithm for the identifier, which
* can be the link of the item or the id of the item.
*/
const generateItemId = (sourceId: string, identifier: string): string => {
return `${sourceId}-${new Md5().update(identifier).toString()}`;
const generateItemId = async (
sourceId: string,
identifier: string,
): Promise<string> => {
return `${sourceId}-${await utils.md5(identifier)}`;
};
/**

View File

@@ -1,4 +1,4 @@
import { decode, encode } from 'std/hex';
import { decodeHex, encodeHex } from 'std/hex';
import {
FEEDDECK_ENCRYPTION_IV,
FEEDDECK_ENCRYPTION_KEY,
@@ -20,10 +20,8 @@ export const generateKey = async (): Promise<
);
const rawKey = new Uint8Array(await crypto.subtle.exportKey('raw', key));
return {
rawKey: new TextDecoder().decode(encode(rawKey)),
iv: new TextDecoder().decode(
encode(crypto.getRandomValues(new Uint8Array(16))),
),
rawKey: encodeHex(rawKey),
iv: encodeHex(crypto.getRandomValues(new Uint8Array(16))),
};
};
@@ -33,9 +31,7 @@ export const generateKey = async (): Promise<
* using the `generateKey` function.
*/
export const encrypt = async (plainText: string): Promise<string> => {
const rawKey = decode(
new TextEncoder().encode(FEEDDECK_ENCRYPTION_KEY),
);
const rawKey = decodeHex(FEEDDECK_ENCRYPTION_KEY);
const key = await crypto.subtle.importKey(
'raw',
rawKey.buffer,
@@ -43,9 +39,7 @@ export const encrypt = async (plainText: string): Promise<string> => {
true,
['encrypt', 'decrypt'],
);
const iv = decode(
new TextEncoder().encode(FEEDDECK_ENCRYPTION_IV),
);
const iv = decodeHex(FEEDDECK_ENCRYPTION_IV);
const encrypted = await crypto.subtle.encrypt(
{ name: 'AES-CBC', iv },
@@ -53,7 +47,7 @@ export const encrypt = async (plainText: string): Promise<string> => {
new TextEncoder().encode(plainText),
);
const encryptedBytes = new Uint8Array(encrypted);
return new TextDecoder().decode(encode(encryptedBytes));
return encodeHex(encryptedBytes);
};
/**
@@ -62,9 +56,7 @@ export const encrypt = async (plainText: string): Promise<string> => {
* generated using the `generateKey` function.
*/
export const decrypt = async (encryptedText: string): Promise<string> => {
const rawKey = decode(
new TextEncoder().encode(FEEDDECK_ENCRYPTION_KEY),
);
const rawKey = decodeHex(FEEDDECK_ENCRYPTION_KEY);
const key = await crypto.subtle.importKey(
'raw',
rawKey.buffer,
@@ -72,14 +64,12 @@ export const decrypt = async (encryptedText: string): Promise<string> => {
true,
['encrypt', 'decrypt'],
);
const iv = decode(
new TextEncoder().encode(FEEDDECK_ENCRYPTION_IV),
);
const iv = decodeHex(FEEDDECK_ENCRYPTION_IV);
const decrypted = await crypto.subtle.decrypt(
{ name: 'AES-CBC', iv },
key,
decode(new TextEncoder().encode(encryptedText)),
decodeHex(encryptedText),
);
const decryptedBytes = new Uint8Array(decrypted);
return new TextDecoder().decode(decryptedBytes);

View File

@@ -1,7 +1,12 @@
import { fetchWithTimeout } from './fetchWithTimeout.ts';
import { log } from './log.ts';
import { md5 } from './md5.ts';
import { decrypt, encrypt } from './encrypt.ts';
export const utils = {
fetchWithTimeout,
log,
md5,
encrypt,
decrypt,
};

View File

@@ -0,0 +1,12 @@
import { crypto } from 'std/crypto';
import { encode } from 'std/hex';
export const md5 = async (str: string): Promise<string> => {
return new TextDecoder().decode(
encode(
new Uint8Array(
await crypto.subtle.digest('MD5', new TextEncoder().encode(str)),
),
),
);
};

View File

@@ -2,15 +2,15 @@
"imports": {
"std/assert": "https://deno.land/std@0.208.0/assert/mod.ts",
"std/testing/mock": "https://deno.land/std@0.208.0/testing/mock.ts",
"std/server": "https://deno.land/std@0.177.0/http/server.ts",
"std/md5": "https://deno.land/std@0.119.0/hash/md5.ts",
"std/hex": "https://deno.land/std@0.177.0/encoding/hex.ts",
"@supabase/supabase-js": "https://esm.sh/@supabase/supabase-js@2.7.1",
"rss": "https://deno.land/x/rss@0.5.8/mod.ts",
"rss/types": "https://deno.land/x/rss@0.5.8/src/types/mod.ts",
"std/server": "https://deno.land/std@0.208.0/http/server.ts",
"std/hex": "https://deno.land/std@0.208.0/encoding/hex.ts",
"std/crypto": "https://deno.land/std@0.208.0/crypto/mod.ts",
"@supabase/supabase-js": "https://esm.sh/@supabase/supabase-js@2.39.0",
"rss": "https://deno.land/x/rss@1.0.0/mod.ts",
"rss/types": "https://deno.land/x/rss@1.0.0/src/types/mod.ts",
"cheerio": "https://esm.sh/cheerio@1.0.0-rc.12",
"lodash": "https://raw.githubusercontent.com/lodash/lodash/4.17.21-es/lodash.js",
"redis": "https://deno.land/x/redis@v0.29.4/mod.ts",
"stripe": "https://esm.sh/stripe@12.9.0?target=deno&no-check"
"redis": "https://deno.land/x/redis@v0.32.0/mod.ts",
"stripe": "https://esm.sh/stripe@14.8.0?target=deno&no-check"
}
}