2023-03-23 14:05:59 +01:00
|
|
|
import extName from 'ext-name';
|
|
|
|
|
|
|
|
|
|
const getCommentMediaInfo = (comment) => {
|
|
|
|
|
if (!comment?.thumbnailUrl && !comment?.link) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-04-15 18:12:46 +02:00
|
|
|
// if (comment?.thumbnailUrl) {
|
|
|
|
|
// return {
|
|
|
|
|
// url: comment.link,
|
|
|
|
|
// type: 'webpage'
|
|
|
|
|
// };
|
|
|
|
|
// }
|
2023-03-23 14:05:59 +01:00
|
|
|
if (comment?.link) {
|
2023-04-12 17:09:12 +02:00
|
|
|
try {
|
|
|
|
|
new URL(comment.link);
|
|
|
|
|
} catch (error) {
|
2023-04-23 16:39:40 +02:00
|
|
|
// console.error("Invalid URL:", comment.link);
|
2023-04-12 17:09:12 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mime = extName(new URL(comment?.link).pathname.replace('/', ''))[0]?.mime;
|
|
|
|
|
|
2023-03-23 14:05:59 +01:00
|
|
|
if (mime?.startsWith('image')) {
|
|
|
|
|
return {
|
|
|
|
|
url: comment.link,
|
|
|
|
|
type: 'image'
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mime?.startsWith('video')) {
|
|
|
|
|
return {
|
|
|
|
|
url: comment.link,
|
|
|
|
|
type: 'video'
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mime?.startsWith('audio')) {
|
|
|
|
|
return {
|
|
|
|
|
url: comment.link,
|
|
|
|
|
type: 'audio'
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-12 17:09:12 +02:00
|
|
|
export default getCommentMediaInfo;
|