Skip to content

Commit

Permalink
Retrieve resource and send to the Wallet Backend service. No longer c…
Browse files Browse the repository at this point in the history
…alling the collect endpoint
  • Loading branch information
jholleran committed Jul 25, 2024
1 parent ef3fac3 commit 2411b15
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
31 changes: 17 additions & 14 deletions api/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,29 @@ export const fetchFiles = async (): Promise<WalletFile[]> => {
};

export const postFile = async (file: FileObject): Promise<void> => {
console.log(process.env.EXPO_PUBLIC_WALLET_API);

const formData = new FormData();
formData.append("file", {
name: file.name,
type: mime.getType(file.name) || "application/octet-stream",
type: file.contentType || mime.getType(file.name) || "application/octet-stream",

Check failure on line 38 in api/files.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Insert `⏎·····`
uri: file.uri,
} as unknown as Blob);

await fetch(`${process.env.EXPO_PUBLIC_WALLET_API}/wallet`, {
method: "PUT",
body: formData,
});
try {
const response = await fetch(`${process.env.EXPO_PUBLIC_WALLET_API}/wallet`, {

Check failure on line 43 in api/files.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Replace ``${process.env.EXPO_PUBLIC_WALLET_API}/wallet`,` with `⏎······`${process.env.EXPO_PUBLIC_WALLET_API}/wallet`,⏎·····`
method: "PUT",
body: formData,
});

Check failure on line 46 in api/files.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Replace `}` with `··}⏎····`

if (response.ok) {
console.debug("Uploaded file to Wallet. HTTP response status:" + response.status);

Check failure on line 49 in api/files.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Replace `··console.debug("Uploaded·file·to·Wallet.·HTTP·response·status:"·+·response.status` with `console.debug(⏎········"Uploaded·file·to·Wallet.·HTTP·response·status:"·+·response.status⏎······`

Check failure on line 49 in api/files.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Unexpected string concatenation
} else {
throw Error("Failed to upload file to Wallet. HTTP response status from Wallet Backend service:" +

Check failure on line 51 in api/files.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Insert `⏎········`

Check failure on line 51 in api/files.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Unexpected string concatenation
response.status);

Check failure on line 52 in api/files.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Replace `response.status` with `··response.status⏎······`
}
} catch (error) {
throw Error("Failed to retrieve and upload file to Wallet", { cause: error });

Check failure on line 55 in api/files.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Replace `·cause:·error` with `⏎······cause:·error,⏎···`
}

Check failure on line 56 in api/files.ts

View workflow job for this annotation

GitHub Actions / lint / lint

Delete `⏎`

};

export const deleteFile = async (fileId: string): Promise<void> => {
Expand All @@ -57,10 +67,3 @@ export const getFile = async (fileId: string): Promise<Blob> => {
"GET"
);
};

export const collectFileToPod = async (uri: string): Promise<Blob> => {
return makeApiRequest<Blob>(
`wallet/collect?url=${encodeURIComponent(uri)}`,
"PUT"
);
};
14 changes: 11 additions & 3 deletions app/(tabs)/home/download.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { useLocalSearchParams, useNavigation } from "expo-router";
import { ThemedText } from "@/components/ThemedText";
import CustomButton from "@/components/Button";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { collectFileToPod } from "@/api/files";
import { postFile } from "@/api/files";
import { FontAwesome6 } from "@expo/vector-icons";
import IconResourceName from "@/components/common/IconResourceName";
import { RDF_CONTENT_TYPE } from "@/utils/constants";
Expand All @@ -41,10 +41,14 @@ const Page: React.FC<FileDetailProps> = () => {
const parentNavigation = useNavigation("/(tabs)");

const mutation = useMutation({
mutationFn: collectFileToPod,
mutationFn: postFile,
onSuccess: async () => {
await queryClient.invalidateQueries({ queryKey: ["files"] });
},
onError: (error) => {
// TODO: there needs to be better error handling here...
console.warn(error)
},
mutationKey: ["filesMutation"],
});
const { uri, contentType } = useLocalSearchParams();
Expand All @@ -56,7 +60,11 @@ const Page: React.FC<FileDetailProps> = () => {

const { goBack } = useNavigation();
const onSaveToWallet = async () => {
mutation.mutate(uri as string);
mutation.mutate({
uri: uri as String,
name: fileName,
contentType: contentType
})
goBack();
};
useLayoutEffect(() => {
Expand Down

0 comments on commit 2411b15

Please sign in to comment.