Skip to content

Commit

Permalink
change way to valid metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Sworzen1 committed May 8, 2024
1 parent 3a8d4d9 commit b1ce62f
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 25 deletions.
5 changes: 0 additions & 5 deletions govtool/frontend/src/models/metadataValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ export type ValidateMetadataResult = {
metadata?: any;
};

export enum MetadataStandard {
CIP108 = "CIP108",
}

export type MetadataValidationDTO = {
url: string;
hash: string;
standard?: MetadataStandard;
};
12 changes: 2 additions & 10 deletions govtool/frontend/src/services/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,11 @@ import { NavigateFunction } from "react-router-dom";

import { PATHS } from "@consts";

const TIMEOUT_IN_SECONDS = 30 * 1000; // 1000 ms is 1 s then its 10 s
const TIMEOUT_IN_SECONDS = 30 * 1000; // 1000 ms is 1 s then its 30 s
const BASE_URL = import.meta.env.VITE_BASE_URL;

// Validation should be performed directly on the server
// than no metadata service is needed and `/api` might be removed
export const API = axios.create({
baseURL: `${BASE_URL}/api`,
timeout: TIMEOUT_IN_SECONDS,
});

// TODO: Remove this service and use the API service
export const METADATA_VALIDATION_API = axios.create({
baseURL: `${BASE_URL}/metadata-validation`,
baseURL: `${BASE_URL}`,
timeout: TIMEOUT_IN_SECONDS,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { MetadataValidationDTO, ValidateMetadataResult } from "@models";
import { METADATA_VALIDATION_API } from "../../API";
import { API } from "@services";

export const postValidate = async (body: MetadataValidationDTO) => {
const response = await METADATA_VALIDATION_API.post<ValidateMetadataResult>(
`/validate`,
const response = await API.post<ValidateMetadataResult>(
`/metadata/validate`,
body,
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { vi } from "vitest";
import { postValidate } from "@services";
import { checkIsMissingGAMetadata } from "..";
import { MetadataStandard, MetadataValidationStatus } from "@/models";
import { MetadataValidationStatus } from "@/models";

const url = "https://example.com";
const hash = "abcdefg";
Expand All @@ -28,7 +28,6 @@ describe("checkIsMissingGAMetadata", () => {
expect(mockPostValidate).toHaveBeenCalledWith({
url,
hash,
standard: MetadataStandard.CIP108,
});
});

Expand All @@ -44,7 +43,6 @@ describe("checkIsMissingGAMetadata", () => {
expect(mockPostValidate).toHaveBeenCalledWith({
url,
hash,
standard: MetadataStandard.CIP108,
});
});

Expand All @@ -60,7 +58,6 @@ describe("checkIsMissingGAMetadata", () => {
expect(mockPostValidate).toHaveBeenCalledWith({
url,
hash,
standard: MetadataStandard.CIP108,
});
});

Expand All @@ -73,7 +70,6 @@ describe("checkIsMissingGAMetadata", () => {
expect(mockPostValidate).toHaveBeenCalledWith({
url,
hash,
standard: MetadataStandard.CIP108,
});
});
});
3 changes: 1 addition & 2 deletions govtool/frontend/src/utils/validateMetadataHash.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { postValidate } from "@services";

import { MetadataStandard, MetadataValidationStatus } from "@/models";
import { MetadataValidationStatus } from "@/models";

type CheckIsMissingGAMetadataResponse = {
status?: MetadataValidationStatus;
Expand All @@ -20,7 +20,6 @@ export const checkIsMissingGAMetadata = async ({
const { status, metadata, valid } = await postValidate({
url,
hash,
standard: MetadataStandard.CIP108,
});
if (status) {
return { status, valid };
Expand Down

0 comments on commit b1ce62f

Please sign in to comment.