Ma77Ball commented on code in PR #5675:
URL: https://github.com/apache/texera/pull/5675#discussion_r3576652624


##########
frontend/src/app/common/util/media-type.util.ts:
##########
@@ -0,0 +1,37 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+export function isVideoUrl(value: string): boolean {
+  if (typeof value !== "string") return false;
+  return (
+    value.match(/\.(mp4|webm|ogv)(\?.*)?$/i) !== null ||
+    value.startsWith("data:video/") ||
+    value.startsWith("https://v3b.fal.media/files/";)
+  );
+}
+
+export function isAudioUrl(value: string): boolean {
+  if (typeof value !== "string") return false;
+  return value.match(/\.(mp3|wav|ogg|m4a|flac)(\?.*)?$/i) !== null || 
value.startsWith("data:audio/");
+}
+
+export function isImageUrl(value: string): boolean {
+  if (typeof value !== "string") return false;
+  return value.match(/\.(png|jpg|jpeg|gif|webp)(\?.*)?$/i) !== null || 
value.startsWith("data:image/");
+}

Review Comment:
   The extension checks match any bare string ending in a media-like token, so 
an ordinary text or filename cell such as `report.png` or `song.mp3` in a 
non-HuggingFace result column now renders as (usually broken) media across 
every result table. Tighten the extension match to require a real URL (http(s) 
or data:). This also broadens the hardcoded `v3b` fal subdomain, which can 
rotate. The 19 existing spec cases still pass.
   
   ```suggestion
   export function isVideoUrl(value: string): boolean {
     if (typeof value !== "string") return false;
     return (
       /^https?:\/\/.+\.(mp4|webm|ogv)(\?.*)?$/i.test(value) ||
       value.startsWith("data:video/") ||
       /^https:\/\/[a-z0-9-]+\.fal\.media\/files\//i.test(value)
     );
   }
   
   export function isAudioUrl(value: string): boolean {
     if (typeof value !== "string") return false;
     return /^https?:\/\/.+\.(mp3|wav|ogg|m4a|flac)(\?.*)?$/i.test(value) || 
value.startsWith("data:audio/");
   }
   
   export function isImageUrl(value: string): boolean {
     if (typeof value !== "string") return false;
     return /^https?:\/\/.+\.(png|jpg|jpeg|gif|webp)(\?.*)?$/i.test(value) || 
value.startsWith("data:image/");
   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to