Repository: mandiant/capa
File: web/explorer/src/composables/useRdocLoader.js (JavaScript)

Code before:
/**
 * Copyright 2024 Google LLC
 *
 * Licensed 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 { useToast } from "primevue/usetoast";
import { isGzipped, decompressGzip, readFileAsText } from "@/utils/fileUtils";

const VT_REANALYZE_SUGGESTION =
    " If this is a VirusTotal or similar link, the file may need to be reanalyzed. Try again later.";

export function useRdocLoader() {
    const toast = useToast();
    const MIN_SUPPORTED_VERSION = "7.0.0";

    /**
     * Displays a toast notification.
     * @param {string} severity - The severity level of the notification
     * @param {string} summary - The title of the notification.
     * @param {string} detail - The detailed message of the notification.
     * @returns {void}
     */
    const showToast = (severity, summary, detail) => {
        toast.add({ severity, summary, detail, life: 3000, group: "bc" }); // bc: bottom-center
    };

    /**
     * Validates that the parsed object has the expected result document schema.
     * @param {Object} rdoc - The parsed JSON data.
     * @returns {{ valid: boolean, message?: string }} Validation result with an optional error message.
     */
    const validateRdocSchema = (rdoc) => {
        const isInvalidObject = (v) => !v || typeof v !== "object" || Array.isArray(v);

        if (isInvalidObject(rdoc)) {

Review comment (suggestion):
```suggestion
    "If this is a VirusTotal or similar link, the file may need to be reanalyzed. Try again later.";
```

Code after:
/**
 * Copyright 2024 Google LLC
 *
 * Licensed 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 { useToast } from "primevue/usetoast";
import { isGzipped, decompressGzip, readFileAsText } from "@/utils/fileUtils";

const VT_REANALYZE_SUGGESTION =
    "If this is a VirusTotal or similar link, the file may need to be reanalyzed. Try again later.";

export function useRdocLoader() {
    const toast = useToast();
    const MIN_SUPPORTED_VERSION = "7.0.0";

    /**
     * Displays a toast notification.
     * @param {string} severity - The severity level of the notification
     * @param {string} summary - The title of the notification.
     * @param {string} detail - The detailed message of the notification.
     * @returns {void}
     */
    const showToast = (severity, summary, detail) => {
        toast.add({ severity, summary, detail, life: 3000, group: "bc" }); // bc: bottom-center
    };

    /**
     * Validates that the parsed object has the expected result document schema.
     * @param {Object} rdoc - The parsed JSON data.
     * @returns {{ valid: boolean, message?: string }} Validation result with an optional error message.
     */
    const validateRdocSchema = (rdoc) => {
        const isInvalidObject = (v) => !v || typeof v !== "object" || Array.isArray(v);

        if (isInvalidObject(rdoc)) {