ELin2025 commented on code in PR #5567:
URL: https://github.com/apache/texera/pull/5567#discussion_r3399910146


##########
frontend/src/app/workspace/component/hugging-face-audio-upload/hugging-face-audio-upload.component.ts:
##########
@@ -0,0 +1,153 @@
+/**
+ * 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.
+ */
+
+import { Component, OnDestroy, OnInit } from "@angular/core";
+import { CommonModule } from "@angular/common";
+import { FieldType, FieldTypeConfig } from "@ngx-formly/core";
+import { HttpClient } from "@angular/common/http";
+import { NzButtonModule } from "ng-zorro-antd/button";
+import { firstValueFrom } from "rxjs";
+import { AppSettings } from "../../../common/app-setting";
+
+interface HuggingFaceAudioUploadResponse {
+  path: string;
+  fileName: string;
+}
+
+@Component({
+  selector: "texera-hugging-face-audio-upload",
+  templateUrl: "./hugging-face-audio-upload.component.html",
+  styleUrls: ["./hugging-face-audio-upload.component.scss"],
+  imports: [CommonModule, NzButtonModule],
+})
+export class HuggingFaceAudioUploadComponent extends 
FieldType<FieldTypeConfig> implements OnInit, OnDestroy {
+  fileName = "";
+  errorMessage = "";
+  isUploading = false;
+  private localPreviewUrl = "";
+
+  ngOnInit(): void {
+    if (typeof this.formControl.value === "string" && 
this.formControl.value.trim().length > 0) {
+      this.fileName = this.getDisplayName(this.formControl.value);
+    }
+  }
+
+  constructor(private http: HttpClient) {
+    super();
+  }
+
+  get previewSrc(): string {
+    if (this.localPreviewUrl) {
+      return this.localPreviewUrl;
+    }
+    const value = this.formControl.value;
+    if (typeof value !== "string" || value.trim().length === 0) {
+      return "";
+    }
+    if (value.startsWith("data:audio/")) {
+      return value;
+    }
+    return 
`${AppSettings.getApiEndpoint()}/huggingface/audio-preview?path=${encodeURIComponent(value)}`;
+  }
+
+  ngOnDestroy(): void {
+    this.revokePreviewUrl();
+  }
+
+  async onFileSelected(event: Event): Promise<void> {
+    this.errorMessage = "";
+    const input = event.target as HTMLInputElement;
+    const file = input.files?.[0];
+
+    if (!file) {
+      return;
+    }
+    if (!file.type.startsWith("audio/")) {
+      this.errorMessage = "Choose an audio file.";
+      input.value = "";
+      return;
+    }
+    this.revokePreviewUrl();
+    this.localPreviewUrl = URL.createObjectURL(file);
+    this.isUploading = true;

Review Comment:
   Done



##########
frontend/src/app/workspace/component/hugging-face-audio-upload/hugging-face-audio-upload.component.spec.ts:
##########
@@ -0,0 +1,33 @@
+/**
+ * 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.
+ */
+
+import { HuggingFaceAudioUploadComponent } from 
"./hugging-face-audio-upload.component";
+
+describe("HuggingFaceAudioUploadComponent (unit)", () => {
+  it("should be defined", () => {
+    expect(HuggingFaceAudioUploadComponent).toBeDefined();
+  });
+
+  it("should have the correct selector", () => {
+    const metadata = 
Reflect.getOwnPropertyDescriptor(HuggingFaceAudioUploadComponent, 
"__annotations");
+    // Component decorator metadata is available via the Angular compiler;
+    // at minimum verify the class is importable and constructable metadata 
exists.
+    expect(HuggingFaceAudioUploadComponent.prototype).toBeDefined();
+  });

Review Comment:
   Done



-- 
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