Skip to content

Commit

Permalink
Logs output to log for file uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
dmf444 committed Mar 7, 2024
1 parent a63af2c commit 786edbb
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/main/FileUploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class FileUploader {
public async upload() {
let data = new FormData();


log.info("Loading files.")
if (this.file.savedLocation != null) {
data.set('original_file', fs.createReadStream(this.file.savedLocation), this.file.fileName);
}
Expand All @@ -28,30 +28,41 @@ export class FileUploader {
if (this.file.fileMetadata.coverImage != null && this.file.fileMetadata.coverImage !== "") {
data.set('custom_preview', fs.createReadStream(this.file.fileMetadata.coverImage));
}
log.info("Loading files complete.")

let saveName = this.file.fileMetadata.localizedName == null ? this.file.fileName : this.file.fileMetadata.localizedName;
log.info("Loading names.")
data.set('save_name', saveName);
data.set('container', this.file.fileMetadata.container);
log.info("Loading container.")
data.set('description', this.completeJson(this.file.fileMetadata.description, this.file.fileMetadata.descriptionVersion));
log.info("Loading desc.")
data.set('desc_version', this.file.fileMetadata.descriptionVersion);
log.info("Loading desc vers.")
if (!this.file.fileMetadata.descriptionVersion.startsWith("1")) {
log.info("Loading PC.")
data.set('page_count', this.file.fileMetadata.pageCount);
}
log.info("Loading date.")
data.set('date', this.file.fileMetadata.date ?? "");
log.info("Loading restriction.")
data.set('restriction', this.file.fileMetadata.restrictions);
log.info("Loading tags.")
if(this.file.fileMetadata.tags.length == 0) {
data.append('tags[]', []);
}
this.file.fileMetadata.tags.forEach(tag => {
data.append('tags[]', tag);
});
if (this.getGroup() != null) {
log.info("Loading group.")
data.set('group_id', this.getGroup());
}

let urlBase = this._settings.getUrl();
if (urlBase.slice(-1) !== "/") urlBase += "/";
let endPoint = !this.file.fileMetadata.descriptionVersion.startsWith("1") ? "endpoint=document" : "endpoint=image";
log.info("URL selected.")
/*fetch(urlBase + "api/upload.php?" + endPoint,
{
method: "post",
Expand All @@ -71,6 +82,7 @@ export class FileUploader {
headers.append('Content-Type', data.headers["Content-Type"]);
headers.append('Authorization', 'Basic ' + Buffer.from(`${this._settings.getUsername()}:${this._settings.getPassword()}`).toString('base64'));
}
log.info("Loading POSTING.")
await this.connect(urlBase + "api/upload.php?" + endPoint, {method: "post", body: data.stream, headers: headers, mode: "no-cors"});
}

Expand Down Expand Up @@ -125,4 +137,4 @@ export class FileUploader {
return null;
}

}
}

0 comments on commit 786edbb

Please sign in to comment.