1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-20 16:07:45 +01:00

lint fixes

This commit is contained in:
Kyle Spearrin 2017-11-04 21:37:35 -04:00
parent 11edb0261b
commit 8e998ff179
5 changed files with 81 additions and 77 deletions

View File

@ -2,41 +2,44 @@ import { CipherString } from '../domain/cipherString';
export default abstract class Domain {
protected buildDomainModel(model: any, obj: any, map: any, alreadyEncrypted: boolean, notEncList: any = []) {
for (var prop in map) {
if (map.hasOwnProperty(prop)) {
var objProp = obj[(map[prop] || prop)];
if (alreadyEncrypted === true || notEncList.indexOf(prop) > -1) {
model[prop] = objProp ? objProp : null;
} else {
model[prop] = objProp ? new CipherString(objProp) : null;
}
for (const prop in map) {
if (!map.hasOwnProperty(prop)) {
continue;
}
const objProp = obj[(map[prop] || prop)];
if (alreadyEncrypted === true || notEncList.indexOf(prop) > -1) {
model[prop] = objProp ? objProp : null;
} else {
model[prop] = objProp ? new CipherString(objProp) : null;
}
}
}
protected async decryptObj(model: any, self: any, map: any, orgId: string) {
var promises = [];
for (let prop in map) {
const promises = [];
for (const prop in map) {
if (!map.hasOwnProperty(prop)) {
continue;
}
// tslint:disable-next-line
(function (theProp) {
let promise = Promise.resolve().then(function () {
var mapProp = map[theProp] || theProp;
const p = Promise.resolve().then(() => {
const mapProp = map[theProp] || theProp;
if (self[mapProp]) {
return self[mapProp].decrypt(orgId);
}
return null;
}).then(function (val) {
}).then((val: any) => {
model[theProp] = val;
return;
});
promises.push(promise);
promises.push(p);
})(prop);
}
await Promise.all(promises);
return model;
}
}
}

View File

@ -1,7 +1,7 @@
import { CipherString } from './cipherString';
import { FolderData } from '../data/folderData'
import { FolderData } from '../data/folderData';
import Domain from './domain'
import { CipherString } from './cipherString';
import Domain from './domain';
class Folder extends Domain {
id: string;
@ -9,24 +9,23 @@ class Folder extends Domain {
constructor(obj?: FolderData, alreadyEncrypted: boolean = false) {
super();
if(obj == null) {
if (obj == null) {
return;
}
this.buildDomainModel(this, obj, {
id: null,
name: null
name: null,
}, alreadyEncrypted, ['id']);
}
async decrypt(): Promise<any> {
var self = this;
var model = {
id: self.id
const model = {
id: this.id,
};
return await this.decryptObj(model, this, {
name: null
name: null,
}, null);
}
}

View File

@ -32,7 +32,7 @@ import ServicesModule from './services/services.module';
import LockModule from './lock/lock.module';
// Model imports
import { Folder } from './models/domain/folder';
import { Folder } from '../../models/domain/folder';
import { AttachmentData } from '../../models/data/attachmentData';
import { CardData } from '../../models/data/cardData';

View File

@ -82,10 +82,10 @@ export default class ApiService {
const response = await fetch(new Request(this.identityBaseUrl + '/connect/token', {
body: this.qsStringify(request.toIdentityToken()),
cache: 'no-cache',
headers: {
headers: new Headers({
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
'Accept': 'application/json',
},
}),
method: 'POST',
}));
@ -114,9 +114,9 @@ export default class ApiService {
const response = await fetch(new Request(this.baseUrl + '/two-factor/send-email-login', {
body: JSON.stringify(request),
cache: 'no-cache',
headers: {
headers: new Headers({
'Content-Type': 'application/json; charset=utf-8',
},
}),
method: 'POST',
}));
@ -132,10 +132,10 @@ export default class ApiService {
const authHeader = await this.handleTokenState();
const response = await fetch(new Request(this.baseUrl + '/accounts/revision-date', {
cache: 'no-cache',
headers: {
headers: new Headers({
Accept: 'application/json',
Authorization: authHeader,
},
}),
}));
if (response.status === 200) {
@ -150,9 +150,9 @@ export default class ApiService {
const response = await fetch(new Request(this.baseUrl + '/accounts/password-hint', {
body: JSON.stringify(request),
cache: 'no-cache',
headers: {
headers: new Headers({
'Content-Type': 'application/json; charset=utf-8',
},
}),
method: 'POST',
}));
@ -166,9 +166,9 @@ export default class ApiService {
const response = await fetch(new Request(this.baseUrl + '/accounts/register', {
body: JSON.stringify(request),
cache: 'no-cache',
headers: {
headers: new Headers({
'Content-Type': 'application/json; charset=utf-8',
},
}),
method: 'POST',
}));
@ -185,11 +185,11 @@ export default class ApiService {
const response = await fetch(new Request(this.baseUrl + '/folders', {
body: JSON.stringify(request),
cache: 'no-cache',
headers: {
headers: new Headers({
'Accept': 'application/json',
'Authorization': authHeader,
'Content-Type': 'application/json; charset=utf-8',
},
}),
method: 'POST',
}));
@ -207,11 +207,11 @@ export default class ApiService {
const response = await fetch(new Request(this.baseUrl + '/folders/' + id, {
body: JSON.stringify(request),
cache: 'no-cache',
headers: {
headers: new Headers({
'Accept': 'application/json',
'Authorization': authHeader,
'Content-Type': 'application/json; charset=utf-8',
},
}),
method: 'PUT',
}));
@ -228,9 +228,9 @@ export default class ApiService {
const authHeader = await this.handleTokenState();
const response = await fetch(new Request(this.baseUrl + '/folders/' + id, {
cache: 'no-cache',
headers: {
headers: new Headers({
Authorization: authHeader,
},
}),
method: 'DELETE',
}));
@ -247,11 +247,11 @@ export default class ApiService {
const response = await fetch(new Request(this.baseUrl + '/ciphers', {
body: JSON.stringify(request),
cache: 'no-cache',
headers: {
headers: new Headers({
'Accept': 'application/json',
'Authorization': authHeader,
'Content-Type': 'application/json; charset=utf-8',
},
}),
method: 'POST',
}));
@ -269,11 +269,11 @@ export default class ApiService {
const response = await fetch(new Request(this.baseUrl + '/ciphers/' + id, {
body: JSON.stringify(request),
cache: 'no-cache',
headers: {
headers: new Headers({
'Accept': 'application/json',
'Authorization': authHeader,
'Content-Type': 'application/json; charset=utf-8',
},
}),
method: 'PUT',
}));
@ -290,9 +290,9 @@ export default class ApiService {
const authHeader = await this.handleTokenState();
const response = await fetch(new Request(this.baseUrl + '/ciphers/' + id, {
cache: 'no-cache',
headers: {
headers: new Headers({
Authorization: authHeader,
},
}),
method: 'DELETE',
}));
@ -309,10 +309,10 @@ export default class ApiService {
const response = await fetch(new Request(this.baseUrl + '/ciphers/' + id + '/attachment', {
body: data,
cache: 'no-cache',
headers: {
headers: new Headers({
Accept: 'application/json',
Authorization: authHeader,
},
}),
method: 'POST',
}));
@ -329,9 +329,9 @@ export default class ApiService {
const authHeader = await this.handleTokenState();
const response = await fetch(new Request(this.baseUrl + '/ciphers/' + id + '/attachment/' + attachmentId, {
cache: 'no-cache',
headers: {
headers: new Headers({
Authorization: authHeader,
},
}),
method: 'DELETE',
}));
@ -347,10 +347,10 @@ export default class ApiService {
const authHeader = await this.handleTokenState();
const response = await fetch(new Request(this.baseUrl + '/sync', {
cache: 'no-cache',
headers: {
headers: new Headers({
Accept: 'application/json',
Authorization: authHeader,
},
}),
}));
if (response.status === 200) {
@ -407,10 +407,10 @@ export default class ApiService {
refresh_token: refreshToken,
}),
cache: 'no-cache',
headers: {
headers: new Headers({
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
'Accept': 'application/json',
},
}),
method: 'POST',
}));

View File

@ -1,8 +1,10 @@
import { CipherString } from '../models/domain/cipherString';
import { Folder } from '../models/domain/folder';
import { FolderData } from '../models/data/folderData';
import { FolderResponse } from '../models/response/folderResponse';
import { FolderRequest } from '../models/request/folderRequest';
import { FolderResponse } from '../models/response/folderResponse';
import ApiService from './api.service';
import ConstantsService from './constants.service';
@ -11,14 +13,14 @@ import UserService from './user.service';
import UtilsService from './utils.service';
const Keys = {
foldersPrefix: 'folders_'
foldersPrefix: 'folders_',
};
export default class FolderService {
decryptedFolderCache: any[];
constructor(private cryptoService: CryptoService, private userService: UserService, private i18nService: any, private apiService: ApiService) {
constructor(private cryptoService: CryptoService, private userService: UserService,
private i18nService: any, private apiService: ApiService) {
}
clearCache(): void {
@ -31,10 +33,10 @@ export default class FolderService {
return folder;
}
async get(id:string): Promise<Folder> {
async get(id: string): Promise<Folder> {
const userId = await this.userService.getUserId();
const folders = await UtilsService.getObjFromStorage<Map<string, FolderData>>(Keys.foldersPrefix + userId);
if(folders == null || !folders.has(id)) {
if (folders == null || !folders.has(id)) {
return null;
}
@ -44,7 +46,7 @@ export default class FolderService {
async getAll(): Promise<Folder[]> {
const userId = await this.userService.getUserId();
const folders = await UtilsService.getObjFromStorage<Map<string, FolderData>>(Keys.foldersPrefix + userId);
const response:Folder[] = [];
const response: Folder[] = [];
folders.forEach((folder) => {
response.push(new Folder(folder));
});
@ -58,17 +60,17 @@ export default class FolderService {
const decFolders: any[] = [{
id: null,
name: this.i18nService.noneFolder
name: this.i18nService.noneFolder,
}];
const key = await this.cryptoService.getKey();
if(key == null) {
if (key == null) {
throw new Error('No key.');
}
const promises = [];
const folders = await this.getAll();
for(const folder of folders) {
for (const folder of folders) {
promises.push(folder.decrypt().then((f: any) => {
decFolders.push(f);
}));
@ -79,11 +81,11 @@ export default class FolderService {
return this.decryptedFolderCache;
}
async saveWithServer (folder: Folder): Promise<any> {
async saveWithServer(folder: Folder): Promise<any> {
const request = new FolderRequest(folder);
let response: FolderResponse;
if(folder.id == null) {
if (folder.id == null) {
response = await this.apiService.postFolder(request);
folder.id = response.id;
} else {
@ -98,15 +100,15 @@ export default class FolderService {
async upsert(folder: FolderData | FolderData[]): Promise<any> {
const userId = await this.userService.getUserId();
let folders = await UtilsService.getObjFromStorage<Map<string, FolderData>>(Keys.foldersPrefix + userId);
if(folders == null) {
if (folders == null) {
folders = new Map<string, FolderData>();
}
if(folder instanceof FolderData) {
if (folder instanceof FolderData) {
const f = folder as FolderData;
folders.set(f.id, f);
} else {
for(const f of (folder as FolderData[])) {
for (const f of (folder as FolderData[])) {
folders.set(f.id, f);
}
}
@ -115,29 +117,29 @@ export default class FolderService {
this.decryptedFolderCache = null;
}
async replace (folders: FolderData[]): Promise<any> {
async replace(folders: FolderData[]): Promise<any> {
const userId = await this.userService.getUserId();
await UtilsService.saveObjToStorage(Keys.foldersPrefix + userId, folders);
this.decryptedFolderCache = null;
}
async clear(userId: string): Promise<any> {
await UtilsService.removeFromStorage(Keys.foldersPrefix + userId);
await UtilsService.removeFromStorage(Keys.foldersPrefix + userId);
this.decryptedFolderCache = null;
}
async delete(id: string | string[]): Promise<any> {
const userId = await this.userService.getUserId();
let folders = await UtilsService.getObjFromStorage<Map<string, FolderData>>(Keys.foldersPrefix + userId);
if(folders == null) {
const folders = await UtilsService.getObjFromStorage<Map<string, FolderData>>(Keys.foldersPrefix + userId);
if (folders == null) {
return;
}
if(id instanceof String) {
if (id instanceof String) {
const i = id as string;
folders.delete(i);
} else {
for(const i of (id as string[])) {
for (const i of (id as string[])) {
folders.delete(i);
}
}