Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

bayfiles media host support #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/bayfiles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import fetch from "node-fetch";

//todo: some sort of 5min cache or something?
export async function rawUrl(fullUrl) {
const res = await fetch(fullUrl);

const text = await res.text();
const [, url] = /<a href="(https:\/\/cdn-\d{2}.+)">/.exec(text);
//const url = text.substring(2983, 3042)

return url;
}

export function isBayfiles(fullUrl) {
return (
fullUrl.startsWith("https://bayfiles.com/") ||
fullUrl.startsWith("https://anonfile.com/") ||
fullUrl.startsWith("https://megaupload.nz/")
);
}
5 changes: 5 additions & 0 deletions src/resolvers/IMedia.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { now } from "./util";
import { linkMedia } from "./Mutations/medias";
import { ObjectID } from "mongodb";
import { rawUrl, isBayfiles } from "../bayfiles";

export function __resolveType({ type }) {
return type === "EPISODE" ? "Episode" : "Media";
Expand Down Expand Up @@ -30,6 +31,10 @@ export function comment({ id }, { content }, context) {
});
}

export function content({ id }, { content }, context) {
return isBayfiles(content) ? rawUrl(content) : content;
}

export function comments_count({ id }, args, context) {
return context.db
.collection("comments")
Expand Down