From 1647c7c2543f67fc3275df800f7b50cb1ed67a3d Mon Sep 17 00:00:00 2001 From: Elias Crum Date: Thu, 6 Jun 2024 19:05:55 +0200 Subject: [PATCH 1/3] something wrong with authentication --- src/components/PodUpload.vue | 17 ++++-- src/components/Styling/TheHeader.vue | 5 ++ src/components/fileUpload.ts | 87 ++++++++++++++++------------ src/components/mime_types.js | 87 ++++++++++++++++++++++++++++ 4 files changed, 154 insertions(+), 42 deletions(-) create mode 100644 src/components/mime_types.js diff --git a/src/components/PodUpload.vue b/src/components/PodUpload.vue index e61fd85..5426fd0 100644 --- a/src/components/PodUpload.vue +++ b/src/components/PodUpload.vue @@ -50,7 +50,7 @@ -
+
-
+
diff --git a/src/components/fileUpload.ts b/src/components/fileUpload.ts index 81ce71c..2b20a1e 100644 --- a/src/components/fileUpload.ts +++ b/src/components/fileUpload.ts @@ -4,14 +4,14 @@ import { overwriteFile, } from "@inrupt/solid-client"; import { fetch } from "@inrupt/solid-client-authn-browser"; - +import { mimeTypes } from "./mime_types.js"; /** * Fetches a logged-in user's Pod URLs using a webID. - * + * * @param webid The webID URL of the current user. * @returns A Promise that resolves to a string[] of user Pod URLs, if available, or `undefined` if no pods are found. -*/ + */ async function getPodURLs(webid: string): Promise { let pods: string[] = []; try { @@ -24,54 +24,67 @@ async function getPodURLs(webid: string): Promise { /** * Iterates through a FileList and uploads files to a Solid Pod via the uploadToPod() method. - * + * * @param fileList The list of files to be uploaded to the Pod. * @param podURL The URL of the Pod files are to be uploaded to. -*/ + */ function handleFiles(fileList: FileList, podURL: string) { + const outputList = [] Array.from(fileList).forEach((file: File) => { uploadToPod(`${podURL}uploads/${file.name}`, file, fetch); }); + } /** - * Takes in a File and upload is to a Solid Pod using the @inrupt/solid-client method overwriteFile(). - * + * Converts a file extension into a MIME Type for use in HTTP PUT requests. + * The function relies on the hash map contained in the file 'mime_types.js'. + * + * @param fileExtension The file extension string of the file for which the MIME Type should be found. + * @returns The MIME Type string of the file of interest or 'application/octet-stream' if not in the hash map. + */ +function getMimeType(fileExtension: string) { + console.log(fileExtension) + return mimeTypes[fileExtension.toLowerCase()] || "application/octet-stream"; +} + +/** + * Takes in a File and uploads it to a Solid Pod using the @inrupt/solid-client method overwriteFile(). + * * The directory designated in targetURL does not need to exist before execuation. + * The contentType of the uploaded file is determined by the getMineType() method using the file's extension. * The overwriteFile() method will create the conatiner (directory) path if it does not already exist. - * + * * @param targetURL The URL where the files are to be uploaded. * @param file The file that is to be uploaded to the Pod. * @param fetch A window.fetch that includes the current User's credentials (to allow for Write access). - * @returns A Promise that resolves to a string[] of user Pod URLs, if available, or `undefined` if no pods are found. -*/ -async function uploadToPod(targetURL: string, file: File, fetch): Promise { - if (file.type != '') { - // for if the file type is captured by the well-known "secret codes" - try { - const savedFile = await overwriteFile(targetURL, file, { - contentType: file.type, - fetch: fetch, - }); - console.log(`File saved at ${targetURL}`); - console.log(savedFile) - return true - } catch (error) { - console.error(error); - } - } else { - // for if the file type is not captured by the well-known "secret codes" - try { - const savedFile = await overwriteFile(targetURL, file, { - fetch: fetch, - }); - console.log(`File saved at ${targetURL}`); - console.log(savedFile) - return true - } catch (error) { - console.error(error); - } + * @returns A Promise that resolves to a File & WithResourceInfo of the uploaded files. + */ +async function uploadToPod( + targetURL: string, + file: File, + fetch +): Promise { + console.log(file.type, getMimeType('.' + file.name.split('.')[file.name.split('.').length - 1])) + try { + const savedFile = await overwriteFile(targetURL, file, { + contentType: getMimeType('.' + file.name.split('.')[file.name.split('.').length - 1]), + fetch: fetch, + }); + console.log(`File saved at ${targetURL}`); + console.log(savedFile); + return savedFile; + } catch (error) { + console.error(error); + } +} + +function derefrenceFile(inputFile: File & WithResourceInfo): string[] { + try { + return [inputFile.name, String(inputFile.size), inputFile.internal_resourceInfo.sourceIri] + } catch (error) { + console.error('Error', error) } } -export { handleFiles, getPodURLs }; +export { handleFiles, getPodURLs, getMimeType, derefrenceFile }; diff --git a/src/components/mime_types.js b/src/components/mime_types.js new file mode 100644 index 0000000..ec7880f --- /dev/null +++ b/src/components/mime_types.js @@ -0,0 +1,87 @@ +const mimeTypes = { + // Common file types + '.aac': 'audio/aac', + '.abw': 'application/x-abiword', + '.arc': 'application/x-freearc', + '.avi': 'video/x-msvideo', + '.azw': 'application/vnd.amazon.ebook', + '.bin': 'application/octet-stream', + '.bmp': 'image/bmp', + '.bz': 'application/x-bzip', + '.bz2': 'application/x-bzip2', + '.csh': 'application/x-csh', + '.css': 'text/css', + '.csv': 'text/csv', + '.doc': 'application/msword', + '.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + '.eot': 'application/vnd.ms-fontobject', + '.epub': 'application/epub+zip', + '.gz': 'application/gzip', + '.gif': 'image/gif', + '.htm': 'text/html', + '.html': 'text/html', + '.ico': 'image/vnd.microsoft.icon', + '.ics': 'text/calendar', + '.jar': 'application/java-archive', + '.jpeg': 'image/jpeg', + '.jpg': 'image/jpeg', + '.js': 'text/javascript', + '.json': 'application/json', + '.jsonld': 'application/ld+json', + '.mid': 'audio/midi', + '.midi': 'audio/midi', + '.mjs': 'text/javascript', + '.mp3': 'audio/mpeg', + '.mpeg': 'video/mpeg', + '.mpkg': 'application/vnd.apple.installer+xml', + '.odp': 'application/vnd.oasis.opendocument.presentation', + '.ods': 'application/vnd.oasis.opendocument.spreadsheet', + '.odt': 'application/vnd.oasis.opendocument.text', + '.oga': 'audio/ogg', + '.ogv': 'video/ogg', + '.ogx': 'application/ogg', + '.opus': 'audio/opus', + '.otf': 'font/otf', + '.png': 'image/png', + '.pdf': 'application/pdf', + '.php': 'application/x-httpd-php', + '.ppt': 'application/vnd.ms-powerpoint', + '.pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation', + '.rar': 'application/vnd.rar', + '.rtf': 'application/rtf', + '.sh': 'application/x-sh', + '.svg': 'image/svg+xml', + '.swf': 'application/x-shockwave-flash', + '.tar': 'application/x-tar', + '.tif': 'image/tiff', + '.tiff': 'image/tiff', + '.ts': 'video/mp2t', + '.ttf': 'font/ttf', + '.txt': 'text/plain', + '.vsd': 'application/vnd.visio', + '.wav': 'audio/wav', + '.weba': 'audio/webm', + '.webm': 'video/webm', + '.webp': 'image/webp', + '.woff': 'font/woff', + '.woff2': 'font/woff2', + '.xhtml': 'application/xhtml+xml', + '.xls': 'application/vnd.ms-excel', + '.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + '.xml': 'application/xml', + '.xul': 'application/vnd.mozilla.xul+xml', + '.zip': 'application/zip', + '.3gp': 'video/3gpp', + '.3g2': 'video/3gpp2', + '.7z': 'application/x-7z-compressed', + + // RDF file types + '.rdf': 'application/rdf+xml', + '.owl': 'application/rdf+xml', + '.n3': 'text/n3', + '.nt': 'application/n-triples', + '.ttl': 'text/turtle', + '.trig': 'application/trig', +}; + +export { mimeTypes } \ No newline at end of file From 572f8150e09be034ba1252944758f5aa85f1677e Mon Sep 17 00:00:00 2001 From: Elias Crum Date: Sat, 8 Jun 2024 13:20:03 +0200 Subject: [PATCH 2/3] fixed upload message but still not great --- src/components/PodUpload.vue | 86 ++++++++++++++++++++---------------- src/components/fileUpload.ts | 41 ++++++++++++----- 2 files changed, 77 insertions(+), 50 deletions(-) diff --git a/src/components/PodUpload.vue b/src/components/PodUpload.vue index 5426fd0..f58d6b3 100644 --- a/src/components/PodUpload.vue +++ b/src/components/PodUpload.vue @@ -50,40 +50,41 @@ -
+
Try logging out and logging back in!Try logging out and logging back in!(also try clearing browser + hostory if problem reoccurs)
-
- -
- (File(s) can be found in the - {{ this.pod }}uploads/ directory of your pod) -
- - -
- There seems to be an error with the file upload. There are some - file types not supported in the current implementation. We are - working on fixing this currently. Sorry!! -
+ + +
+ (File(s) can be found in the {{ this.pod }}uploads/ directory + of your pod) +
+ + +
+ There seems to be an error with the file upload. There are some file + types not supported in the current implementation. We are working on + fixing this currently. Sorry!!
@@ -102,7 +103,7 @@