Skip to content

Commit

Permalink
on my way
Browse files Browse the repository at this point in the history
  • Loading branch information
ddecrulle committed Dec 5, 2024
1 parent 9268809 commit a510887
Show file tree
Hide file tree
Showing 16 changed files with 184 additions and 61 deletions.
17 changes: 17 additions & 0 deletions web/src/core/adapters/s3Client/s3Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,23 @@ export function createS3Client(
);

return downloadUrl;
},

headObject: async ({ path }) => {
const { bucketName, objectName } = bucketNameAndObjectNameFromS3Path(path);

const { getAwsS3Client } = await prApi;

const { awsS3Client } = await getAwsS3Client();

const head = await awsS3Client.send(
new (await import("@aws-sdk/client-s3")).HeadObjectCommand({
Bucket: bucketName,
Key: objectName
})
);

return { contentType: head.ContentType, metadata: head.Metadata };
}

// "getPresignedUploadUrl": async ({ path, validityDurationSecond }) => {
Expand Down
5 changes: 5 additions & 0 deletions web/src/core/ports/S3Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ export type S3Client = {
validityDurationSecond: number;
}) => Promise<string>;

headObject: (params: { path: string }) => Promise<{
contentType: string | undefined;
metadata: Record<string, string> | undefined;
}>;

// getPresignedUploadUrl: (params: {
// path: string;
// validityDurationSecond: number;
Expand Down
1 change: 1 addition & 0 deletions web/src/core/usecases/dataExplorer/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type State = {
rows: any[];
rowCount: number | undefined;
fileDownloadUrl: string;
// fileType: "parquet" | "csv" | "json";
}
| undefined;
};
Expand Down
120 changes: 89 additions & 31 deletions web/src/core/usecases/dataExplorer/thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,46 @@ import { assert } from "tsafe/assert";
import * as s3ConfigManagement from "core/usecases/s3ConfigManagement";

const privateThunks = {
getFileDonwloadUrl:
(params: { sourceUrl: string }) =>
async (...args) => {
const [dispatch, , { oidc }] = args;

const { sourceUrl } = params;

const fileDownloadUrl = await (async () => {
if (sourceUrl.startsWith("https://")) {
return sourceUrl;
}

const s3path = sourceUrl.replace(/^s3:\/\//, "/");
assert(s3path !== sourceUrl, "Unsupported protocol");

if (!oidc.isUserLoggedIn) {
oidc.login({ doesCurrentHrefRequiresAuth: true });
await new Promise(() => {});
}

const s3Client = (
await dispatch(
s3ConfigManagement.protectedThunks.getS3ConfigAndClientForExplorer()
)
)?.s3Client;

if (s3Client === undefined) {
alert("No S3 client available");
await new Promise<never>(() => {});
assert(false);
}

return s3Client.getFileDownloadUrl({
path: s3path,
validityDurationSecond: 3600 * 6
});
})();

return fileDownloadUrl;
},
performQuery:
(params: {
queryParams: {
Expand All @@ -28,7 +68,7 @@ const privateThunks = {

dispatch(actions.queryStarted({ queryParams }));

const { sqlOlap, oidc } = rootContext;
const { sqlOlap } = rootContext;

const getIsActive = () => same(getState()[name].queryParams, queryParams);

Expand All @@ -49,36 +89,11 @@ const privateThunks = {
};
}

const fileDownloadUrl = await (async () => {
if (sourceUrl.startsWith("https://")) {
return sourceUrl;
}

const s3path = sourceUrl.replace(/^s3:\/\//, "/");
assert(s3path !== sourceUrl, "Unsupported protocol");

if (!oidc.isUserLoggedIn) {
oidc.login({ doesCurrentHrefRequiresAuth: true });
await new Promise(() => {});
}

const s3Client = (
await dispatch(
s3ConfigManagement.protectedThunks.getS3ConfigAndClientForExplorer()
)
)?.s3Client;

if (s3Client === undefined) {
alert("No S3 client available");
await new Promise<never>(() => {});
assert(false);
}

return s3Client.getFileDownloadUrl({
path: s3path,
validityDurationSecond: 3600 * 6
});
})();
const fileDownloadUrl = await dispatch(
privateThunks.getFileDonwloadUrl({
sourceUrl
})
);

const rowCountOrErrorMessage = await sqlOlap
.getRowCount(sourceUrl)
Expand Down Expand Up @@ -132,6 +147,49 @@ const privateThunks = {
fileDownloadUrl
})
);
},
detectFileType:
(params: { sourceUrl: string }) =>
async (...args) => {
const { sourceUrl } = params;
const [dispatch] = args;

const extension = (() => {
const validExtensions = ["parquet", "csv", "json"] as const;
type ValidExtension = (typeof validExtensions)[number];

const isValidExtension = (ext: string): ext is ValidExtension =>
validExtensions.includes(ext as ValidExtension);

let pathname: string;

try {
pathname = new URL(sourceUrl).pathname;
} catch {
return undefined;
}
const match = pathname.match(/\.(\w+)$/);

if (match === null) {
return undefined;
}

const [, extension] = match;

return isValidExtension(extension) ? extension : undefined;
})();

if (extension) {
return extension;
}

const contentType = await (async () => {
const fileDownloadUrl = await dispatch(
privateThunks.getFileDonwloadUrl({
sourceUrl
})
);
})();
}
} satisfies Thunks;

Expand Down
3 changes: 2 additions & 1 deletion web/src/ui/i18n/resources/de.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,8 @@ Fühlen Sie sich frei, Ihre Kubernetes-Bereitstellungen zu erkunden und die Kont
"resize table": undefined
},
UrlInput: {
load: "Laden"
load: "Laden",
reset: "Leeren"
},
CommandBar: {
ok: "Ok"
Expand Down
11 changes: 8 additions & 3 deletions web/src/ui/i18n/resources/en.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ export const translations: Translations<"en"> = {
our documentation
</MuiLink>
. &nbsp;
<MuiLink {...accountTabLink}>Configure the minio clients</MuiLink>.
<MuiLink {...accountTabLink}>
Configure the minio clients
</MuiLink>.
</>
)
},
Expand Down Expand Up @@ -345,7 +347,9 @@ export const translations: Translations<"en"> = {
our documentation
</MuiLink>
. &nbsp;
<MuiLink {...accountTabLink}>Configure your local Vault CLI</MuiLink>.
<MuiLink {...accountTabLink}>
Configure your local Vault CLI
</MuiLink>.
</>
)
},
Expand Down Expand Up @@ -950,7 +954,8 @@ Feel free to explore and take charge of your Kubernetes deployments!
"resize table": "Resize"
},
UrlInput: {
load: "Load"
load: "Load",
reset: "Reset"
},
CommandBar: {
ok: "Ok"
Expand Down
15 changes: 11 additions & 4 deletions web/src/ui/i18n/resources/es.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,9 @@ export const translations: Translations<"en"> = {
nuestra documentación
</MuiLink>
. &nbsp;
<MuiLink {...accountTabLink}>Configura los clientes de minio</MuiLink>.
<MuiLink {...accountTabLink}>
Configura los clientes de minio
</MuiLink>.
</>
)
},
Expand Down Expand Up @@ -357,7 +359,9 @@ export const translations: Translations<"en"> = {
nuestra documentación
</MuiLink>
. &nbsp;
<MuiLink {...accountTabLink}>Configura tu Vault CLI local</MuiLink>.
<MuiLink {...accountTabLink}>
Configura tu Vault CLI local
</MuiLink>.
</>
)
},
Expand Down Expand Up @@ -955,7 +959,9 @@ export const translations: Translations<"en"> = {
específica del archivo copiando la URL de la barra de direcciones.
<br />
¿No estás seguro por dónde empezar? ¡Prueba este{" "}
<MuiLink {...demoParquetFileLink}>archivo de demostración</MuiLink>!
<MuiLink {...demoParquetFileLink}>
archivo de demostración
</MuiLink>!
</>
),
column: "columna",
Expand All @@ -964,7 +970,8 @@ export const translations: Translations<"en"> = {
"resize table": "Redimensionar"
},
UrlInput: {
load: "Cargar"
load: "Cargar",
reset: "Vaciar"
},
CommandBar: {
ok: "Aceptar"
Expand Down
7 changes: 5 additions & 2 deletions web/src/ui/i18n/resources/fi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,9 @@ export const translations: Translations<"fi"> = {
dokumentaatiomme
</MuiLink>
. &nbsp;
<MuiLink {...accountTabLink}>Määritä paikallinen Vault CLI</MuiLink>.
<MuiLink {...accountTabLink}>
Määritä paikallinen Vault CLI
</MuiLink>.
</>
)
},
Expand Down Expand Up @@ -956,7 +958,8 @@ Tutustu vapaasti ja ota hallintaan Kubernetes-julkaisusi!
"resize table": "Muuta taulukon kokoa"
},
UrlInput: {
load: "Lataa"
load: "Lataa",
reset: "Tyhjennä"
},
CommandBar: {
ok: "ok"
Expand Down
15 changes: 11 additions & 4 deletions web/src/ui/i18n/resources/fr.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,9 @@ export const translations: Translations<"fr"> = {
notre documentation
</MuiLink>
. &nbsp;
<MuiLink {...accountTabLink}>Configurer les clients MinIO</MuiLink>.
<MuiLink {...accountTabLink}>
Configurer les clients MinIO
</MuiLink>.
</>
)
},
Expand Down Expand Up @@ -359,7 +361,9 @@ export const translations: Translations<"fr"> = {
notre documentation
</MuiLink>
. &nbsp;
<MuiLink {...accountTabLink}>Configurer votre Vault CLI local</MuiLink>.
<MuiLink {...accountTabLink}>
Configurer votre Vault CLI local
</MuiLink>.
</>
)
},
Expand Down Expand Up @@ -965,7 +969,9 @@ N'hésitez pas à explorer et à prendre en main vos déploiements Kubernetes !
spécifique du fichier en copiant l'URL de la barre d'adresse.
<br />
Vous ne savez pas par où commencer ? Essayez ce{" "}
<MuiLink {...demoParquetFileLink}>fichier de démonstration</MuiLink> !
<MuiLink {...demoParquetFileLink}>
fichier de démonstration
</MuiLink> !
</>
),
column: "colonne",
Expand All @@ -974,7 +980,8 @@ N'hésitez pas à explorer et à prendre en main vos déploiements Kubernetes !
"resize table": "Redimensionner"
},
UrlInput: {
load: "Charger"
load: "Charger",
reset: "Vider"
},
CommandBar: {
ok: "ok"
Expand Down
12 changes: 8 additions & 4 deletions web/src/ui/i18n/resources/it.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,9 @@ export const translations: Translations<"it"> = {
la nostra documentazione
</MuiLink>
. &nbsp;
<MuiLink {...accountTabLink}>Configurare i client MinIO</MuiLink>.
<MuiLink {...accountTabLink}>
Configurare i client MinIO
</MuiLink>.
</>
)
},
Expand Down Expand Up @@ -354,8 +356,9 @@ export const translations: Translations<"it"> = {
la nostra documentazione
</MuiLink>
. &nbsp;
<MuiLink {...accountTabLink}>Configurare il tuo Vault CLI locale</MuiLink>
.
<MuiLink {...accountTabLink}>
Configurare il tuo Vault CLI locale
</MuiLink>.
</>
)
},
Expand Down Expand Up @@ -965,7 +968,8 @@ Sentiti libero di esplorare e prendere il controllo dei tuoi deployment Kubernet
"resize table": "Ridimensiona"
},
UrlInput: {
load: "Carica"
load: "Carica",
reset: "Svuotare"
},
CommandBar: {
ok: "ok"
Expand Down
7 changes: 5 additions & 2 deletions web/src/ui/i18n/resources/nl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,9 @@ export const translations: Translations<"nl"> = {
onze documentatie
</MuiLink>
. &nbsp;
<MuiLink {...accountTabLink}>Uw lokale Vault CLI instellen</MuiLink>.
<MuiLink {...accountTabLink}>
Uw lokale Vault CLI instellen
</MuiLink>.
</>
)
},
Expand Down Expand Up @@ -967,7 +969,8 @@ Voel je vrij om te verkennen en de controle over je Kubernetes-implementaties te
"resize table": "Formaat wijzigen"
},
UrlInput: {
load: "Laden"
load: "Laden",
reset: "Leegmaken"
},
CommandBar: {
ok: "ok"
Expand Down
Loading

0 comments on commit a510887

Please sign in to comment.