Skip to content
This repository has been archived by the owner on Aug 14, 2024. It is now read-only.

Commit

Permalink
feat: abide to type rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfhound905 committed Jun 29, 2023
1 parent 4b1e228 commit 491ab36
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ const inject = new Injector();
const logger = Logger.plugin("PluginTemplate");
const { toast } = common;

async function fetchQuickVidsLink(content: string) {
async function fetchQuickVidsLink(content: string): Promise<string> {
const response = await fetch(
"https://abstract.land/api/proxy/api.quickvids.win/v1/shorturl/create",
// This proxy is allowed by QuickVids, so we can use it to bypass CORS.
{
method: "POST",
headers: { "Content-Type": "application/json" },
// eslint-disable-next-line @typescript-eslint/naming-convention
body: JSON.stringify({ input_text: content }),
},
);
Expand All @@ -35,7 +36,7 @@ const patterns = [
/(http:|https:\/\/)?(www\.)?instagram\.com\/reel\/([a-zA-Z0-9-_]{5,15})(\/)?(\?.*)?/,
];

async function checkForLinks(content: string): Promise<string[]> {
function checkForLinks(content: string): string[] {
const matchedLinks: string[] = [];

for (const pattern of patterns) {
Expand All @@ -49,8 +50,8 @@ async function checkForLinks(content: string): Promise<string[]> {
return matchedLinks;
}

async function replaceLinks(content: string) {
const links = await checkForLinks(content);
async function replaceLinks(content: string): Promise<string> {
const links = checkForLinks(content);
const originalContent = content;
if (links.length > 0) {
toast.toast(
Expand Down Expand Up @@ -82,9 +83,9 @@ async function replaceLinks(content: string) {
return content;
}

export async function start() {
export function start(): void {
inject.instead(common.messages, "sendMessage", async (args, fn) => {
let content = args[1].content;
let { content } = args[1];
try {
content = await replaceLinks(content);
args[1].content = content;
Expand All @@ -103,6 +104,6 @@ export async function start() {
});
}

export function stop() {
export function stop(): void {
inject.uninjectAll();
}

0 comments on commit 491ab36

Please sign in to comment.