mirror of
https://github.com/syncthing/syncthing.git
synced 2024-11-17 10:58:49 -07:00
add mock in-memory data service
This commit is contained in:
parent
fd0de9eb6c
commit
838b2a6a34
@ -4,6 +4,10 @@ This project was generated with [Angular CLI](https://github.com/angular/angular
|
|||||||
|
|
||||||
## Development server
|
## Development server
|
||||||
|
|
||||||
|
Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
|
||||||
|
|
||||||
|
## Production server
|
||||||
|
|
||||||
Run `ng build --prod --base-href /tech-ui/` and build [syncthing tech-ui branch](https://github.com/kastelo/syncthing/tree/tech-ui). Run `export STTECHUIDIR=/path/to/angular/build/; ./bin/syncthing` and navigate to `http://localhost:8384/tech-ui/`.
|
Run `ng build --prod --base-href /tech-ui/` and build [syncthing tech-ui branch](https://github.com/kastelo/syncthing/tree/tech-ui). Run `export STTECHUIDIR=/path/to/angular/build/; ./bin/syncthing` and navigate to `http://localhost:8384/tech-ui/`.
|
||||||
|
|
||||||
## Code scaffolding
|
## Code scaffolding
|
||||||
|
5
package-lock.json
generated
5
package-lock.json
generated
@ -1790,6 +1790,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz",
|
||||||
"integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU="
|
"integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU="
|
||||||
},
|
},
|
||||||
|
"angular-in-memory-web-api": {
|
||||||
|
"version": "0.10.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/angular-in-memory-web-api/-/angular-in-memory-web-api-0.10.0.tgz",
|
||||||
|
"integrity": "sha512-GzY4lHPR8suREYfgiYiJSBrgq0bdCiFw/LuqW5IsOQfRx98AvS69A5Ehz12oMLy9ABzoGpqmNC5fcFtClDAPqQ=="
|
||||||
|
},
|
||||||
"ansi-colors": {
|
"ansi-colors": {
|
||||||
"version": "3.2.4",
|
"version": "3.2.4",
|
||||||
"resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-3.2.4.tgz",
|
"resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-3.2.4.tgz",
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
"@angular/platform-browser": "~9.0.5",
|
"@angular/platform-browser": "~9.0.5",
|
||||||
"@angular/platform-browser-dynamic": "~9.0.5",
|
"@angular/platform-browser-dynamic": "~9.0.5",
|
||||||
"@angular/router": "~9.0.5",
|
"@angular/router": "~9.0.5",
|
||||||
|
"angular-in-memory-web-api": "^0.10.0",
|
||||||
"component": "^1.1.0",
|
"component": "^1.1.0",
|
||||||
"rxjs": "~6.5.4",
|
"rxjs": "~6.5.4",
|
||||||
"tslib": "^1.10.0",
|
"tslib": "^1.10.0",
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
|
import { environment } from '../environments/environment'
|
||||||
|
|
||||||
export const deviceID = (): String => {
|
export const deviceID = (): String => {
|
||||||
const dID: String = globalThis.metadata['deviceID'];
|
const dID: String = environment.production ? globalThis.metadata['deviceID'] : '12345';
|
||||||
return dID.substring(0, 5)
|
return dID.substring(0, 5)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,8 +15,10 @@ import { FolderListComponent } from './folder-list/folder-list.component';
|
|||||||
import { DeviceListComponent } from './device-list/device-list.component';
|
import { DeviceListComponent } from './device-list/device-list.component';
|
||||||
import { StatusToggleComponent } from './status-toggle/status-toggle.component';
|
import { StatusToggleComponent } from './status-toggle/status-toggle.component';
|
||||||
import { DeviceListDataSource } from './device-list/device-list-datasource';
|
import { DeviceListDataSource } from './device-list/device-list-datasource';
|
||||||
|
import { HttpClientInMemoryWebApiModule } from 'angular-in-memory-web-api';
|
||||||
|
import { InMemoryConfigDataService } from './in-memory-config-data.service';
|
||||||
import { deviceID } from './api-utils';
|
import { deviceID } from './api-utils';
|
||||||
|
import { environment } from '../environments/environment'
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
@ -38,7 +40,9 @@ import { deviceID } from './api-utils';
|
|||||||
HttpClientXsrfModule.withOptions({
|
HttpClientXsrfModule.withOptions({
|
||||||
headerName: 'X-CSRF-Token-' + deviceID(),
|
headerName: 'X-CSRF-Token-' + deviceID(),
|
||||||
cookieName: 'CSRF-Token-' + deviceID(),
|
cookieName: 'CSRF-Token-' + deviceID(),
|
||||||
})
|
}),
|
||||||
|
environment.production ?
|
||||||
|
[] : HttpClientInMemoryWebApiModule.forRoot(InMemoryConfigDataService)
|
||||||
],
|
],
|
||||||
providers: [],
|
providers: [],
|
||||||
bootstrap: [AppComponent]
|
bootstrap: [AppComponent]
|
||||||
|
16
src/app/in-memory-config-data.service.spec.ts
Normal file
16
src/app/in-memory-config-data.service.spec.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { InMemoryConfigDataService } from './in-memory-config-data.service';
|
||||||
|
|
||||||
|
describe('InMemoryDataService', () => {
|
||||||
|
let service: InMemoryConfigDataService;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({});
|
||||||
|
service = TestBed.inject(InMemoryConfigDataService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
114
src/app/in-memory-config-data.service.ts
Normal file
114
src/app/in-memory-config-data.service.ts
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class InMemoryConfigDataService {
|
||||||
|
createDb() {
|
||||||
|
const config = {
|
||||||
|
"version": 15,
|
||||||
|
"folders": [
|
||||||
|
{
|
||||||
|
"id": "GXWxf-3zgnU",
|
||||||
|
"label": "MyFolder",
|
||||||
|
"path": "...",
|
||||||
|
"type": "sendreceive",
|
||||||
|
"devices": [
|
||||||
|
{
|
||||||
|
"deviceID": "..."
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"rescanIntervalS": 60,
|
||||||
|
"ignorePerms": false,
|
||||||
|
"autoNormalize": true,
|
||||||
|
"minDiskFreePct": 1,
|
||||||
|
"versioning": {
|
||||||
|
"type": "simple",
|
||||||
|
"params": {
|
||||||
|
"keep": "5"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"copiers": 0,
|
||||||
|
"pullers": 0,
|
||||||
|
"hashers": 0,
|
||||||
|
"order": "random",
|
||||||
|
"ignoreDelete": false,
|
||||||
|
"scanProgressIntervalS": 0,
|
||||||
|
"pullerSleepS": 0,
|
||||||
|
"pullerPauseS": 0,
|
||||||
|
"maxConflicts": 10,
|
||||||
|
"disableSparseFiles": false,
|
||||||
|
"disableTempIndexes": false,
|
||||||
|
"fsync": false,
|
||||||
|
"invalid": ""
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"devices": [
|
||||||
|
{
|
||||||
|
"deviceID": "...",
|
||||||
|
"name": "Laptop",
|
||||||
|
"addresses": [
|
||||||
|
"dynamic",
|
||||||
|
"tcp://192.168.1.2:22000"
|
||||||
|
],
|
||||||
|
"compression": "metadata",
|
||||||
|
"certName": "",
|
||||||
|
"introducer": false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"gui": {
|
||||||
|
"enabled": true,
|
||||||
|
"address": "127.0.0.1:8384",
|
||||||
|
"user": "Username",
|
||||||
|
"password": "$2a$10$ZFws69T4FlvWwsqeIwL.TOo5zOYqsa/.TxlUnsGYS.j3JvjFTmxo6",
|
||||||
|
"useTLS": false,
|
||||||
|
"apiKey": "pGahcht56664QU5eoFQW6szbEG6Ec2Cr",
|
||||||
|
"insecureAdminAccess": false,
|
||||||
|
"theme": "default"
|
||||||
|
},
|
||||||
|
"options": {
|
||||||
|
"listenAddresses": [
|
||||||
|
"default"
|
||||||
|
],
|
||||||
|
"globalAnnounceServers": [
|
||||||
|
"default"
|
||||||
|
],
|
||||||
|
"globalAnnounceEnabled": true,
|
||||||
|
"localAnnounceEnabled": true,
|
||||||
|
"localAnnouncePort": 21027,
|
||||||
|
"localAnnounceMCAddr": "[ff12::8384]:21027",
|
||||||
|
"maxSendKbps": 0,
|
||||||
|
"maxRecvKbps": 0,
|
||||||
|
"reconnectionIntervalS": 60,
|
||||||
|
"relaysEnabled": true,
|
||||||
|
"relayReconnectIntervalM": 10,
|
||||||
|
"startBrowser": false,
|
||||||
|
"natEnabled": true,
|
||||||
|
"natLeaseMinutes": 60,
|
||||||
|
"natRenewalMinutes": 30,
|
||||||
|
"natTimeoutSeconds": 10,
|
||||||
|
"urAccepted": -1,
|
||||||
|
"urUniqueId": "",
|
||||||
|
"urURL": "https://data.syncthing.net/newdata",
|
||||||
|
"urPostInsecurely": false,
|
||||||
|
"urInitialDelayS": 1800,
|
||||||
|
"restartOnWakeup": true,
|
||||||
|
"autoUpgradeIntervalH": 12,
|
||||||
|
"keepTemporariesH": 24,
|
||||||
|
"cacheIgnoredFiles": false,
|
||||||
|
"progressUpdateIntervalS": 5,
|
||||||
|
"limitBandwidthInLan": false,
|
||||||
|
"minHomeDiskFreePct": 1,
|
||||||
|
"releasesURL": "https://upgrades.syncthing.net/meta.json",
|
||||||
|
"alwaysLocalNets": [],
|
||||||
|
"overwriteRemoteDeviceNamesOnConnect": false,
|
||||||
|
"tempIndexMinBlocks": 10
|
||||||
|
},
|
||||||
|
"ignoredDevices": [],
|
||||||
|
"ignoredFolders": []
|
||||||
|
}
|
||||||
|
console.log("in mem?!?!?", config)
|
||||||
|
return { config };
|
||||||
|
}
|
||||||
|
constructor() { }
|
||||||
|
}
|
@ -8,6 +8,7 @@ import { Folder } from './folder';
|
|||||||
import { Device } from './device';
|
import { Device } from './device';
|
||||||
import { FOLDERS, DEVICES } from './mock-config-data';
|
import { FOLDERS, DEVICES } from './mock-config-data';
|
||||||
import { CookieService } from './cookie.service';
|
import { CookieService } from './cookie.service';
|
||||||
|
import { environment } from '../environments/environment'
|
||||||
import { apiURL } from './api-utils'
|
import { apiURL } from './api-utils'
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
@ -19,13 +20,15 @@ export class SystemConfigService {
|
|||||||
private devices: Device[];
|
private devices: Device[];
|
||||||
private foldersSubject: Subject<Folder[]> = new Subject();
|
private foldersSubject: Subject<Folder[]> = new Subject();
|
||||||
private devicesSubject: Subject<Device[]> = new Subject();
|
private devicesSubject: Subject<Device[]> = new Subject();
|
||||||
private systemConfigUrl = apiURL + '/rest/system/config'; // URL to web api
|
private systemConfigUrl = environment.production ? apiURL + '/rest/system/config' : 'api/config';
|
||||||
|
|
||||||
httpOptions = { headers: new HttpHeaders(this.cookieService.getCSRFHeader()) };
|
private httpOptions;
|
||||||
|
|
||||||
constructor(private http: HttpClient, private cookieService: CookieService) { }
|
constructor(private http: HttpClient, private cookieService: CookieService) { }
|
||||||
|
|
||||||
ngOnInit(): void { }
|
ngOnInit(): void {
|
||||||
|
this.httpOptions = { headers: new HttpHeaders(this.cookieService.getCSRFHeader()) };
|
||||||
|
}
|
||||||
|
|
||||||
getSystemConfig(): Observable<any> {
|
getSystemConfig(): Observable<any> {
|
||||||
return this.http
|
return this.http
|
||||||
|
Loading…
Reference in New Issue
Block a user