Skip to content

Commit

Permalink
feat: disable auth when use the downloadedBlob URL
Browse files Browse the repository at this point in the history
  • Loading branch information
EiffelFly committed Nov 25, 2024
1 parent 70695ff commit e852430
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ import { defaultCodeSnippetStyles } from "../../../constant";
import {
GeneralRecord,
InstillStore,
isDownloadableArtifactBlobURL,
isValidURL,
Nullable,
onTriggerInvalidateCredits,
sendAmplitudeData,
toastInstillError,
useAmplitudeCtx,
useComponentOutputFields,
useDownloadNamespaceObject,
useInstillStore,
usePipelineTriggerRequestForm,
useQueryClient,
Expand Down Expand Up @@ -172,7 +170,6 @@ export const PipelinePlayground = ({
const triggerPipelineRelease = useTriggerNamespacePipelineRelease();
const uploadAndGetDownloadNamespaceObjectURL =
useUploadAndGetDownloadNamespaceObjectURL();
const downloadNamespaceObject = useDownloadNamespaceObject();
async function onTriggerPipeline(formData: z.infer<typeof ValidatorSchema>) {
if (
!routeInfo.isSuccess ||
Expand Down Expand Up @@ -421,56 +418,58 @@ export const PipelinePlayground = ({
}
}

for (const key of downloadedFromArtifactKeys) {
const targetValue = pipelineRunResponse.outputs[0][key];

if (!targetValue) {
continue;
}

if (Array.isArray(targetValue)) {
const downloadedArtifacts: string[] = [];
for (const item of targetValue) {
if (isValidURL(item) && isDownloadableArtifactBlobURL(item)) {
const response = await downloadNamespaceObject.mutateAsync({
payload: {
downloadUrl: item,
},
accessToken,
});

if (!response.ok) {
continue;
}

const blob = await response.blob();
const url = URL.createObjectURL(blob);
downloadedArtifacts.push(url);
}
}
pipelineRunResponse.outputs[0][key] = downloadedArtifacts;
} else {
if (
isValidURL(targetValue) &&
isDownloadableArtifactBlobURL(targetValue)
) {
const response = await downloadNamespaceObject.mutateAsync({
payload: {
downloadUrl: targetValue,
},
accessToken,
});

if (!response.ok) {
continue;
}

const blob = await response.blob();
const url = URL.createObjectURL(blob);
pipelineRunResponse.outputs[0][key] = url;
}
}
}
// Temp disable since the blob download URL's auth is currently
// disabled and is controlled by the expiration date
// for (const key of downloadedFromArtifactKeys) {
// const targetValue = pipelineRunResponse.outputs[0][key];

// if (!targetValue) {
// continue;
// }

// if (Array.isArray(targetValue)) {
// const downloadedArtifacts: string[] = [];
// for (const item of targetValue) {
// if (isValidURL(item) && isDownloadableArtifactBlobURL(item)) {
// const response = await downloadNamespaceObject.mutateAsync({
// payload: {
// downloadUrl: item,
// },
// accessToken,
// });

// if (!response.ok) {
// continue;
// }

// const blob = await response.blob();
// const url = URL.createObjectURL(blob);
// downloadedArtifacts.push(url);
// }
// }
// pipelineRunResponse.outputs[0][key] = downloadedArtifacts;
// } else {
// if (
// isValidURL(targetValue) &&
// isDownloadableArtifactBlobURL(targetValue)
// ) {
// const response = await downloadNamespaceObject.mutateAsync({
// payload: {
// downloadUrl: targetValue,
// },
// accessToken,
// });

// if (!response.ok) {
// continue;
// }

// const blob = await response.blob();
// const url = URL.createObjectURL(blob);
// pipelineRunResponse.outputs[0][key] = url;
// }
// }
// }

setPipelineRunResponse(pipelineRunResponse);
setIsPipelineRunning(false);
Expand Down
116 changes: 57 additions & 59 deletions packages/toolkit/src/view/recipe-editor/input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
GeneralRecord,
InstillStore,
isArtifactRelatedInstillFormat,
isDownloadableArtifactBlobURL,
isValidURL,
Nullable,
useInstillStore,
Expand All @@ -35,7 +34,6 @@ import {
useUserNamespaces,
} from "../../../lib";
import {
useDownloadNamespaceObject,
useGetNamespaceObjectDownloadURL,
useGetNamespaceObjectUploadURL,
useUploadAndGetDownloadNamespaceObjectURL,
Expand Down Expand Up @@ -106,8 +104,6 @@ export const Input = ({
const triggerPipelineRelease = useStreamingTriggerUserPipelineRelease();
const autonomousRecipeUpdater = useAutonomousEditorRecipeUpdater();

const downloadNamespaceObject = useDownloadNamespaceObject();

const uploadAndGetDownloadNamespaceObjectURL =
useUploadAndGetDownloadNamespaceObjectURL();

Expand Down Expand Up @@ -363,61 +359,63 @@ export const Input = ({
if (isPipelineOutputUpdatedEvent(event)) {
newPipelineOutput = event.data.output;

for (const key of downloadedFromArtifactKeys) {
const targetValue = newPipelineOutput[key];

if (!targetValue) {
continue;
}

if (Array.isArray(targetValue)) {
const downloadedArtifacts: string[] = [];
for (const item of targetValue) {
if (
isValidURL(item) &&
isDownloadableArtifactBlobURL(item)
) {
const response =
await downloadNamespaceObject.mutateAsync({
payload: {
downloadUrl: item,
},
accessToken,
});

if (!response.ok) {
continue;
}

const blob = await response.blob();
const url = URL.createObjectURL(blob);
downloadedArtifacts.push(url);
}
}
newPipelineOutput[key] = downloadedArtifacts;
} else {
if (
isValidURL(targetValue) &&
isDownloadableArtifactBlobURL(targetValue)
) {
const response =
await downloadNamespaceObject.mutateAsync({
payload: {
downloadUrl: targetValue,
},
accessToken,
});

if (!response.ok) {
continue;
}

const blob = await response.blob();
const url = URL.createObjectURL(blob);
newPipelineOutput[key] = url;
}
}
}
// Temp disable since the blob download URL's auth is currently
// disabled and is controlled by the expiration date
// for (const key of downloadedFromArtifactKeys) {
// const targetValue = newPipelineOutput[key];

// if (!targetValue) {
// continue;
// }

// if (Array.isArray(targetValue)) {
// const downloadedArtifacts: string[] = [];
// for (const item of targetValue) {
// if (
// isValidURL(item) &&
// isDownloadableArtifactBlobURL(item)
// ) {
// const response =
// await downloadNamespaceObject.mutateAsync({
// payload: {
// downloadUrl: item,
// },
// accessToken,
// });

// if (!response.ok) {
// continue;
// }

// const blob = await response.blob();
// const url = URL.createObjectURL(blob);
// downloadedArtifacts.push(url);
// }
// }
// newPipelineOutput[key] = downloadedArtifacts;
// } else {
// if (
// isValidURL(targetValue) &&
// isDownloadableArtifactBlobURL(targetValue)
// ) {
// const response =
// await downloadNamespaceObject.mutateAsync({
// payload: {
// downloadUrl: targetValue,
// },
// accessToken,
// });

// if (!response.ok) {
// continue;
// }

// const blob = await response.blob();
// const url = URL.createObjectURL(blob);
// newPipelineOutput[key] = url;
// }
// }
// }
}

if (isComponentStatusUpdatedEvent(event)) {
Expand Down

0 comments on commit e852430

Please sign in to comment.