mirror of https://github.com/Squidex/squidex.git
22 changed files with 313 additions and 54 deletions
@ -0,0 +1,58 @@ |
|||
// ==========================================================================
|
|||
// AssetStoreModule.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using Autofac; |
|||
using Microsoft.Extensions.Configuration; |
|||
using Squidex.Infrastructure; |
|||
using Squidex.Infrastructure.Assets; |
|||
using Squidex.Infrastructure.Log; |
|||
|
|||
// ReSharper disable InvertIf
|
|||
|
|||
namespace Squidex.Config.Domain |
|||
{ |
|||
public sealed class AssetStoreModule : Module |
|||
{ |
|||
private IConfiguration Configuration { get; } |
|||
|
|||
public AssetStoreModule(IConfiguration configuration) |
|||
{ |
|||
Configuration = configuration; |
|||
} |
|||
|
|||
protected override void Load(ContainerBuilder builder) |
|||
{ |
|||
var assetStoreType = Configuration.GetValue<string>("assetStore:type"); |
|||
|
|||
if (string.IsNullOrWhiteSpace(assetStoreType)) |
|||
{ |
|||
throw new ConfigurationException("Configure the AssetStore type with 'assetStore:type'."); |
|||
} |
|||
|
|||
if (string.Equals(assetStoreType, "Folder", StringComparison.OrdinalIgnoreCase)) |
|||
{ |
|||
var path = Configuration.GetValue<string>("assetStore:folder:path"); |
|||
|
|||
if (string.IsNullOrWhiteSpace(path)) |
|||
{ |
|||
throw new ConfigurationException("Configure AssetStore Folder path with 'assetStore:folder:path'."); |
|||
} |
|||
|
|||
builder.Register(c => new FolderAssetStore(path, c.Resolve<ISemanticLog>())) |
|||
.As<IAssetStore>() |
|||
.As<IExternalSystem>() |
|||
.SingleInstance(); |
|||
} |
|||
else |
|||
{ |
|||
throw new ConfigurationException($"Unsupported value '{assetStoreType}' for 'assetStore:type', supported: Folder."); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
/* |
|||
* Squidex Headless CMS |
|||
* |
|||
* @license |
|||
* Copyright (c) Sebastian Stehle. All rights reserved |
|||
*/ |
|||
|
|||
export * from './pages/assets-page.component'; |
|||
@ -0,0 +1,9 @@ |
|||
/* |
|||
* Squidex Headless CMS |
|||
* |
|||
* @license |
|||
* Copyright (c) Sebastian Stehle. All rights reserved |
|||
*/ |
|||
|
|||
export * from './declarations'; |
|||
export * from './module'; |
|||
@ -0,0 +1,33 @@ |
|||
/* |
|||
* Squidex Headless CMS |
|||
* |
|||
* @license |
|||
* Copyright (c) Sebastian Stehle. All rights reserved |
|||
*/ |
|||
|
|||
import { NgModule } from '@angular/core'; |
|||
import { RouterModule, Routes } from '@angular/router'; |
|||
|
|||
import { SqxFrameworkModule } from 'shared'; |
|||
|
|||
import { |
|||
AssetsPageComponent |
|||
} from './declarations'; |
|||
|
|||
const routes: Routes = [ |
|||
{ |
|||
path: '', |
|||
component: AssetsPageComponent |
|||
} |
|||
]; |
|||
|
|||
@NgModule({ |
|||
imports: [ |
|||
SqxFrameworkModule, |
|||
RouterModule.forChild(routes) |
|||
], |
|||
declarations: [ |
|||
AssetsPageComponent |
|||
] |
|||
}) |
|||
export class SqxFeatureAssetsModule { } |
|||
@ -0,0 +1,19 @@ |
|||
<sqx-title message="{app} | Assets" parameter1="app" value1="{{appName() | async}}"></sqx-title> |
|||
|
|||
<sqx-panel panelWidth="60rem"> |
|||
<div class="panel-header"> |
|||
<div class="panel-title-row"> |
|||
<h3 class="panel-title">Assets</h3> |
|||
</div> |
|||
|
|||
<a class="panel-close" routerLink="../"> |
|||
<i class="icon-close"></i> |
|||
</a> |
|||
</div> |
|||
|
|||
<div class="panel-main"> |
|||
<div class="panel-content panel-content-scroll"> |
|||
|
|||
</div> |
|||
</div> |
|||
</sqx-panel> |
|||
@ -0,0 +1,2 @@ |
|||
@import '_vars'; |
|||
@import '_mixins'; |
|||
@ -0,0 +1,31 @@ |
|||
/* |
|||
* Squidex Headless CMS |
|||
* |
|||
* @license |
|||
* Copyright (c) Sebastian Stehle. All rights reserved |
|||
*/ |
|||
|
|||
import { Component } from '@angular/core'; |
|||
|
|||
import { |
|||
AppComponentBase, |
|||
AppsStoreService, |
|||
fadeAnimation, |
|||
NotificationService, |
|||
UsersProviderService |
|||
} from 'shared'; |
|||
|
|||
@Component({ |
|||
selector: 'sqx-assets-page', |
|||
styleUrls: ['./assets-page.component.scss'], |
|||
templateUrl: './assets-page.component.html', |
|||
animations: [ |
|||
fadeAnimation |
|||
] |
|||
}) |
|||
export class AssetsPageComponent extends AppComponentBase { |
|||
constructor(apps: AppsStoreService, notifications: NotificationService, users: UsersProviderService) { |
|||
super(notifications, users, apps); |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,52 @@ |
|||
/* |
|||
* Squidex Headless CMS |
|||
* |
|||
* @license |
|||
* Copyright (c) Sebastian Stehle. All rights reserved |
|||
*/ |
|||
|
|||
import { Injectable } from '@angular/core'; |
|||
import { Http } from '@angular/http'; |
|||
import { Observable } from 'rxjs'; |
|||
|
|||
import { ApiUrlConfig, EntityCreatedDto } from 'framework'; |
|||
import { AuthService } from './auth.service'; |
|||
|
|||
@Injectable() |
|||
export class AssetsService { |
|||
constructor( |
|||
private readonly http: Http, |
|||
private readonly apiUrl: ApiUrlConfig, |
|||
private readonly authService: AuthService |
|||
) { |
|||
} |
|||
|
|||
public uploadFile(appName: string, file: File): Observable<number | EntityCreatedDto> { |
|||
return new Observable<number | EntityCreatedDto>(subscriber => { |
|||
const url = this.apiUrl.buildUrl(`api/apps/${appName}/schemas`); |
|||
|
|||
const content = new FormData(); |
|||
const headers = new Headers({ |
|||
'Authorization': `${this.authService.user.user.token_type} ${this.authService.user.user.access_token}`, |
|||
'Content-Type': 'multipart/form-data' |
|||
}); |
|||
|
|||
content.append('file', file); |
|||
|
|||
this.http |
|||
.post(url, content, headers) |
|||
.map(response => response.json()) |
|||
.map(response => { |
|||
return new EntityCreatedDto(response.id); |
|||
}) |
|||
.catchError('Failed to upload asset. Please reload.') |
|||
.subscribe(value => { |
|||
subscriber.next(value); |
|||
}, err => { |
|||
subscriber.error(err); |
|||
}, () => { |
|||
subscriber.complete(); |
|||
}); |
|||
}); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue