Skip to content

Commit

Permalink
update TemplateStorage, start OwnCloud support
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfaron committed Sep 20, 2023
1 parent bf8db32 commit 9a0ad58
Show file tree
Hide file tree
Showing 19 changed files with 272 additions and 139 deletions.
61 changes: 48 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"./projects/aas-portal"
],
"devDependencies": {
"@babel/polyfill": "^7.4.4",
"@semantic-release/git": "^10.0.1",
"@semantic-release/gitlab": "^12.0.5"
}
Expand Down
4 changes: 2 additions & 2 deletions projects/aas-lib/package.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
"@ngx-translate/http-loader": "^8.0.0",
"@popperjs/core": "^2.11.8",
"@xmldom/xmldom": "^0.8.10",
"aas-lib": "2.0.0",
"aas-lib": "3.0.0",
"bootstrap": "^5.3.1",
"bootstrap-icons": "^1.10.5",
"chart.js": "^4.3.3",
"common": "2.0.0",
"common": "3.0.0",
"jwt-decode": "^3.1.2",
"lodash-es": "^4.17.21",
"rxjs": "~7.8.1",
Expand Down
4 changes: 2 additions & 2 deletions projects/aas-lib/package.dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
"@ngx-translate/http-loader": "^8.0.0",
"@popperjs/core": "^2.11.8",
"@xmldom/xmldom": "^0.8.10",
"aas-lib": "2.0.0",
"aas-lib": "3.0.0",
"bootstrap": "^5.3.1",
"bootstrap-icons": "^1.10.5",
"chart.js": "^4.3.3",
"common": "2.0.0",
"common": "3.0.0",
"jwt-decode": "^3.1.2",
"lodash-es": "^4.17.21",
"rxjs": "~7.8.1",
Expand Down
4 changes: 2 additions & 2 deletions projects/aas-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
"@ngx-translate/http-loader": "^8.0.0",
"@popperjs/core": "^2.11.8",
"@xmldom/xmldom": "^0.8.10",
"aas-lib": "2.0.0",
"aas-lib": "3.0.0",
"bootstrap": "^5.3.1",
"bootstrap-icons": "^1.10.5",
"chart.js": "^4.3.3",
"common": "2.0.0",
"common": "3.0.0",
"jwt-decode": "^3.1.2",
"lodash-es": "^4.17.21",
"rxjs": "~7.8.1",
Expand Down
1 change: 1 addition & 0 deletions projects/aas-lib/src/lib/auth/auth.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Observable } from 'rxjs';

@Injectable()
export class AuthInterceptor implements HttpInterceptor {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const token = localStorage.getItem('.Token');
if (token) {
Expand Down
2 changes: 2 additions & 0 deletions projects/aas-lib/src/lib/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export class AuthService {
} else {
token = null;
}
} else {
token = null;
}

if (!token) {
Expand Down
4 changes: 2 additions & 2 deletions projects/aas-portal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
"@ngx-translate/http-loader": "^8.0.0",
"@popperjs/core": "^2.11.8",
"@xmldom/xmldom": "^0.8.10",
"aas-lib": "2.0.0",
"aas-lib": "3.0.0",
"bootstrap": "^5.3.1",
"bootstrap-icons": "^1.10.5",
"chart.js": "^4.3.3",
"common": "2.0.0",
"common": "3.0.0",
"jwt-decode": "^3.1.2",
"lodash-es": "^4.17.21",
"rxjs": "~7.8.1",
Expand Down
2 changes: 1 addition & 1 deletion projects/aas-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"dependencies": {
"@xmldom/xmldom": "^0.8.10",
"bcryptjs": "^2.4.3",
"common": "2.0.0",
"common": "3.0.0",
"cors": "^2.8.5",
"express": "^4.18.2",
"form-data": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion projects/aas-server/src/app/aas-provider/directory-scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class DirectoryScan extends AASResourceScan {
public async scanAsync(): Promise<AASDocument[]> {
try {
await this.source.openAsync()
const files = await this.source.getStorage().readdir('.');
const files = await this.source.getStorage().readDir('.');
const documents: AASDocument[] = [];

for (const file of files) {
Expand Down
2 changes: 1 addition & 1 deletion projects/aas-server/src/app/file-storage/file-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export abstract class FileStorage {
public abstract isDirectory(path: string): Promise<boolean>;
public abstract mkdir(path: string, recursive?: boolean): Promise<string | undefined>;
public abstract writeFile(path: string, data: string | Buffer): Promise<void>;
public abstract readdir(path: string): Promise<string[]>;
public abstract readDir(path: string): Promise<string[]>;
public abstract readFile(path: string): Promise<Buffer>;
public abstract unlink(path: string): Promise<void>;
public abstract rename(oldPath: string, newPath: string): Promise<void>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class LocalFileStorage extends FileStorage {
}

public exists(path: string): Promise<boolean> {
return new Promise<boolean>(res => res(fs.existsSync(resolve(this.root, path))));
return Promise.resolve(fs.existsSync(resolve(this.root, path)));
}

public async isDirectory(path: string): Promise<boolean> {
Expand All @@ -39,7 +39,7 @@ export class LocalFileStorage extends FileStorage {
return fs.promises.writeFile(resolve(this.root, path), data);
}

public readdir(path: string): Promise<string[]> {
public readDir(path: string): Promise<string[]> {
return fs.promises.readdir(resolve(this.root, path));
}

Expand Down
53 changes: 36 additions & 17 deletions projects/aas-server/src/app/file-storage/own-cloud-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,56 @@ import { FileStorage } from './file-storage.js';
import ownCloud, { OwnCloudOptions } from 'owncloud-sdk';

export class OwnCloudStorage extends FileStorage {
private promise: Promise<string>;
private oc: ownCloud;

public readonly root: string = '/';
constructor(arg: string | URL) {
super();

public async connect(url: string): Promise<void> {
const temp = new URL(url);
const username = temp.username;
const password = temp.password;
temp.username = '';
temp.password = '';
const url = typeof arg === 'string' ? new URL(arg) : arg;
const username = url.username;
const password = url.password;
url.username = '';
url.password = '';

const options: OwnCloudOptions = {
baseUrl: temp.href
baseUrl: url.href
}

if (username && password) {
options.auth = { basic: { username, password } };
}

const oc = new ownCloud(options);

await oc.login();
this.oc = new ownCloud(options);
this.promise = this.oc.login();
}

public readonly root: string = '/';

public mtime(path: string): Promise<Date> {
throw new Error('Method not implemented.');
}

public exists(path: string): Promise<boolean> {
throw new Error('Method not implemented.');
public async exists(path: string): Promise<boolean> {
try {
await this.promise;
const fileInfo = await this.oc.files.fileInfo(path, {});
return fileInfo != null;
} catch (error) {
throw error;
}
}

public isDirectory(path: string): Promise<boolean> {
throw new Error('Method not implemented.');
public async isDirectory(path: string): Promise<boolean> {
try {
await this.promise;
const fileInfo = await this.oc.files.fileInfo(path, {});
return fileInfo.isDir();
} catch (error) {
throw error;
}
}

public mkdir(path: string, recursive?: boolean | undefined): Promise<string | undefined> {
throw new Error('Method not implemented.');
}
Expand All @@ -52,8 +68,11 @@ export class OwnCloudStorage extends FileStorage {
throw new Error('Method not implemented.');
}

public readdir(path: string): Promise<string[]> {
throw new Error('Method not implemented.');
public async readDir(path: string): Promise<string[]> {
await this.promise;
const fileInfo = await this.oc.files.fileInfo(path, {});
console.log(fileInfo?.isDir);
return [];
}

public readFile(path: string): Promise<Buffer> {
Expand Down
Loading

0 comments on commit 9a0ad58

Please sign in to comment.