diff --git a/front/API.ts b/front/API.ts index 6b3162f..1cc9fe2 100644 --- a/front/API.ts +++ b/front/API.ts @@ -21,7 +21,7 @@ import { PlageHandler } from './models/Plage'; import { ListHandler } from './models/List'; import { AccessTokenResponseHandler } from './models/AccessTokenResponse'; import * as yup from 'yup'; -import { base64ToBlob } from 'file64'; +import { base64ToBlob } from './utils/base64ToBlob'; import { ImagePickerAsset } from 'expo-image-picker'; type AuthenticationInput = { username: string; password: string }; diff --git a/front/package.json b/front/package.json index 4e35b22..eccad8f 100644 --- a/front/package.json +++ b/front/package.json @@ -40,7 +40,6 @@ "expo-secure-store": "~12.0.0", "expo-splash-screen": "~0.17.5", "expo-status-bar": "~1.4.2", - "file64": "^1.0.2", "format-duration": "^2.0.0", "i18next": "^21.8.16", "install": "^0.13.0", diff --git a/front/utils/base64ToBlob.ts b/front/utils/base64ToBlob.ts new file mode 100644 index 0000000..3edf730 --- /dev/null +++ b/front/utils/base64ToBlob.ts @@ -0,0 +1,23 @@ +// SRC: https://github.com/encrypit/file64/blob/master/src/base64-to-blob.ts +export async function base64ToBlob(base64: string): Promise { + const response = await fetch(base64); + let blob = await response.blob(); + const mimeType = getMimeType(base64); + if (mimeType) { + // https://stackoverflow.com/a/50875615 + blob = blob.slice(0, blob.size, mimeType); + } + return blob; +} + +const mimeRegex = /^data:(.+);base64,/; + +/** + * Gets MIME type from Base64. + * + * @param base64 - Base64. + * @returns - MIME type. + */ +function getMimeType(base64: string) { + return base64.match(mimeRegex)?.slice(1, 2).pop(); +} diff --git a/front/yarn.lock b/front/yarn.lock index d7b9acf..dc19c3a 100644 --- a/front/yarn.lock +++ b/front/yarn.lock @@ -9451,11 +9451,6 @@ file-uri-to-path@1.0.0: resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd" integrity sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw== -file64@^1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/file64/-/file64-1.0.2.tgz#d3dde9bab142ccf0049e0bd407a2576e94894825" - integrity sha512-cDQefGBdb8OO7Pb2nXiRcZlVjwgzoG0uuJ/H2fxNdz3vbOZctp0iPJoHDQ4VZrirqGYc9n/p9+ZqptLZrcSGRA== - filesize@6.1.0: version "6.1.0" resolved "https://registry.yarnpkg.com/filesize/-/filesize-6.1.0.tgz#e81bdaa780e2451d714d71c0d7a4f3238d37ad00"