Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix videos not rendering in comments #877

Merged
merged 20 commits into from
Nov 18, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
update isUrlImage and isUrlVideo to use mime
  • Loading branch information
sharunkumar committed Nov 6, 2023
commit 079a051e8ae63c2deed71bda4a18bd76498a2b51
15 changes: 5 additions & 10 deletions src/helpers/lemmy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from "lemmy-js-client";
import { Share } from "@capacitor/share";
import { escapeStringForRegex } from "./regex";
import mime from "mime";

export interface LemmyJWT {
sub: number;
Expand Down Expand Up @@ -235,31 +236,25 @@ export function isUrlImage(url: string): boolean {

try {
parsedUrl = new URL(url);
let mt = mime.getType(url);
return mt?.startsWith("image/") ?? false;
} catch (error) {
console.error(error);
return false;
}

return (
parsedUrl.pathname.endsWith(".jpeg") ||
parsedUrl.pathname.endsWith(".png") ||
parsedUrl.pathname.endsWith(".gif") ||
parsedUrl.pathname.endsWith(".jpg") ||
parsedUrl.pathname.endsWith(".webp")
);
}

export function isUrlVideo(url: string): boolean {
let parsedUrl;

try {
parsedUrl = new URL(url);
let mt = mime.getType(url);
return mt?.startsWith("video/") ?? false;
} catch (error) {
console.error(error);
return false;
}

return parsedUrl.pathname.endsWith(".mp4");
}

export function share(item: Post | Comment) {
Expand Down