Add new AlfrescoContentService in ng2-alfresco-core

- Returns v1 public API endpoints for content and thumbnails
- Refactor getHost(), basePath and similar props into settings
- Use AlfrescoAuthenticationService to get alf_ticket value
This commit is contained in:
Will Abson
2016-06-07 14:02:09 +01:00
parent b8f129ed82
commit e39439b68c
8 changed files with 102 additions and 74 deletions

View File

@@ -0,0 +1,51 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Injectable } from 'angular2/core';
import { AlfrescoAuthenticationService } from './AlfrescoAuthenticationService.service';
import { AlfrescoSettingsService } from './AlfrescoSettingsService.service';
@Injectable()
export class AlfrescoContentService {
constructor(
private settings: AlfrescoSettingsService,
private authService: AlfrescoAuthenticationService
) {
}
/**
* Get thumbnail URL for the given document node.
* @param document Node to get URL for.
* @returns {string} URL address.
*/
getDocumentThumbnailUrl(document: any) {
return this.settings.getApiBaseUrl() + '/nodes/' + document.entry.id +
'/renditions/doclib/content' + '?attachment=false&alf_ticket=' + this.authService.getToken();
}
/**
* Get content URL for the given node.
* @param document Node to get URL for.
* @returns {string} URL address.
*/
getContentUrl(document: any) {
return this.settings.getApiBaseUrl() + '/nodes/' + document.entry.id +
'/content' + '?attachment=false&alf_ticket=' + this.authService.getToken();
}
}

View File

@@ -19,7 +19,10 @@ import { Injectable } from 'angular2/core';
@Injectable()
export class AlfrescoSettingsService {
private _host: string = 'http://127.0.0.1:8080';
private _contextPath = '/alfresco';
private _apiBasePath: string = '/api/-default-/public/alfresco/versions/1';
public get host(): string {
return this._host;
@@ -29,6 +32,10 @@ export class AlfrescoSettingsService {
this._host = value;
}
getApiBaseUrl(): string {
return this._host + this._contextPath + this._apiBasePath;
}
getAuthToken(): string {
// todo: get proper token value
return 'Basic ' + btoa('admin:admin');