Skip to content

Commit

Permalink
Fixed provisioning and publishing issues related to new API version. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
azaslonov authored Aug 27, 2020
1 parent f300e6d commit 3a8e27b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 48 deletions.
7 changes: 4 additions & 3 deletions src/components/content/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class ContentWorkshop {
private readonly authenticator: IAuthenticator,
private readonly settingsProvider: ISettingsProvider,
private readonly logger: Logger
) {}
) { }

public async publish(): Promise<void> {
this.logger.trackEvent("Click: Publish website");
Expand All @@ -30,9 +30,10 @@ export class ContentWorkshop {
}

try {
const accessToken = await this.authenticator.getAccessToken();
const accessToken = await this.authenticator.getAccessToken();

const publishRootUrl = await this.settingsProvider.getSetting<string>("backendUrl") || "";

const publishRootUrl = await this.settingsProvider.getSetting<string>("backendUrl");
const response = await this.httpClient.send({
url: publishRootUrl + "/publish",
method: "POST",
Expand Down
55 changes: 11 additions & 44 deletions src/components/filesystemBlobStorage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as fs from "fs";
import * as path from "path";
import * as mkdirp from "mkdirp";
import { IBlobStorage } from "@paperbits/common/persistence";

export class FileSystemBlobStorage implements IBlobStorage {
Expand All @@ -10,25 +9,16 @@ export class FileSystemBlobStorage implements IBlobStorage {
this.basePath = basePath;
}

public uploadBlob(blobPath: string, content: Uint8Array): Promise<void> {
return new Promise<void>((resolve, reject) => {
const fullpath = `${this.basePath}/${blobPath}`.replace("//", "/");
public async uploadBlob(blobPath: string, content: Uint8Array): Promise<void> {
const fullpath = `${this.basePath}/${blobPath}`.replace("//", "/");

mkdirp(path.dirname(fullpath), (error) => {
if (error) {
reject(error);
throw error;
}
else {
fs.writeFile(fullpath, Buffer.from(content), error => {
if (error) {
reject(error);
}
resolve();
});
}
});
});
try {
await fs.promises.mkdir(path.dirname(fullpath), { recursive: true });
await fs.promises.writeFile(fullpath, Buffer.from(content.buffer));
}
catch (error) {
console.error(error);
}
}

public downloadBlob(blobPath: string): Promise<Uint8Array> {
Expand Down Expand Up @@ -83,30 +73,7 @@ export class FileSystemBlobStorage implements IBlobStorage {
throw new Error("Not supported");
}

public async deleteBlob(filename?: string): Promise<void> {
const deletePath = filename && `${this.basePath}/${filename}`.replace("//", "/") || this.basePath;
if (fs.existsSync(deletePath)) {
if (fs.lstatSync(deletePath).isFile()) {
fs.unlinkSync(deletePath);
} else {
this.deleteFolderRecursive(deletePath);
}
}
}

private deleteFolderRecursive(path: string) {
if (fs.existsSync(path)) {
fs.readdirSync(path).forEach((file) => {
const curPath = path + "/" + file;

if (fs.lstatSync(curPath).isDirectory()) { // recurse
this.deleteFolderRecursive(curPath);
} else { // delete file
fs.unlinkSync(curPath);
}
});

fs.rmdirSync(path);
}
public async deleteBlob(filename: string): Promise<void> {
return null;
}
}
2 changes: 1 addition & 1 deletion src/services/provisioningService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class ProvisionService {
{ name: "Content-Type", value: "application/json" },
{ name: "Authorization", value: accessToken }
],
body: JSON.stringify(contentItem)
body: JSON.stringify({ properties: contentItem })
};

const response = await this.httpClient.send(request);
Expand Down

0 comments on commit 3a8e27b

Please sign in to comment.