Skip to content

Commit e7ca1f7

Browse files
committed
styles: Fix eslint errors
1 parent 718cd12 commit e7ca1f7

4 files changed

Lines changed: 55 additions & 32 deletions

File tree

src/Contracts/DriverContract.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99

1010
import { File } from '@secjs/utils'
1111

12-
interface DriverConstructor {
13-
new (disk: string, ...args): DriverContract
14-
}
15-
1612
export interface DriverContract {
1713
/**
1814
* Put method
@@ -91,4 +87,8 @@ export interface DriverContract {
9187
move(oldFilePath: string, newFilePath: string): Promise<void>
9288
}
9389

94-
declare var DriverContract: DriverConstructor;
90+
interface DriverConstructor {
91+
new (disk: string, ...args): DriverContract
92+
}
93+
94+
declare let DriverContract: DriverConstructor

src/Drivers/LocalDriver.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ export class LocalDriver implements DriverContract {
3838

3939
const file = new File(this.concat(filePath), content)
4040

41-
if (file.originalFileExists) throw new InternalServerException(`File ${filePath} already exists`)
41+
if (file.originalFileExists)
42+
throw new InternalServerException(`File ${filePath} already exists`)
4243

4344
await file.create()
4445
}
@@ -87,7 +88,8 @@ export class LocalDriver implements DriverContract {
8788
async get(filePath: string): Promise<Buffer> {
8889
const file = new File(this.concat(filePath))
8990

90-
if (!file.originalFileExists) throw new InternalServerException(`File ${filePath} does not exist`)
91+
if (!file.originalFileExists)
92+
throw new InternalServerException(`File ${filePath} does not exist`)
9193

9294
return file.getContent()
9395
}
@@ -100,7 +102,8 @@ export class LocalDriver implements DriverContract {
100102
async url(filePath: string): Promise<string> {
101103
const file = new File(this.concat(filePath))
102104

103-
if (!file.originalFileExists) throw new InternalServerException(`File ${filePath} does not exist`)
105+
if (!file.originalFileExists)
106+
throw new InternalServerException(`File ${filePath} does not exist`)
104107

105108
return `${this._url}/${file.base}`
106109
}
@@ -114,9 +117,12 @@ export class LocalDriver implements DriverContract {
114117
async temporaryUrl(filePath: string, time = 900000): Promise<string> {
115118
const file = await new File(this.concat(filePath))
116119

117-
if (!file.originalFileExists) throw new InternalServerException(`File ${filePath} does not exist`)
120+
if (!file.originalFileExists)
121+
throw new InternalServerException(`File ${filePath} does not exist`)
118122

119-
const copy = await file.copy(`storage/temp/${filePath}`, { mockedValues: true })
123+
const copy = await file.copy(`storage/temp/${filePath}`, {
124+
mockedValues: true,
125+
})
120126

121127
setTimeout(() => copy.remove(), time)
122128

@@ -132,7 +138,8 @@ export class LocalDriver implements DriverContract {
132138
async delete(filePath: string, force = false): Promise<void> {
133139
const file = new File(this.concat(filePath))
134140

135-
if (!file.originalFileExists && !force) throw new InternalServerException(`File ${filePath} does not exist`)
141+
if (!file.originalFileExists && !force)
142+
throw new InternalServerException(`File ${filePath} does not exist`)
136143

137144
await promises.rm(this.concat(filePath), { force })
138145
}
@@ -146,7 +153,8 @@ export class LocalDriver implements DriverContract {
146153
async copy(oldFilePath: string, newFilePath: string): Promise<void> {
147154
const file = new File(this.concat(oldFilePath))
148155

149-
if (!file.originalFileExists) throw new InternalServerException(`File ${oldFilePath} does not exist`)
156+
if (!file.originalFileExists)
157+
throw new InternalServerException(`File ${oldFilePath} does not exist`)
150158

151159
await file.copy(this.concat(newFilePath))
152160
}
@@ -160,7 +168,8 @@ export class LocalDriver implements DriverContract {
160168
async move(oldFilePath: string, newFilePath: string): Promise<void> {
161169
const file = new File(this.concat(oldFilePath))
162170

163-
if (!file.originalFileExists) throw new InternalServerException(`File ${oldFilePath} does not exist`)
171+
if (!file.originalFileExists)
172+
throw new InternalServerException(`File ${oldFilePath} does not exist`)
164173

165174
await file.move(this.concat(newFilePath))
166175
}

src/Drivers/S3Driver.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import { S3 } from 'aws-sdk'
1111
import { File } from '@secjs/utils'
1212
import { Config } from '@secjs/config'
13-
import { InternalServerException, NotFoundException } from '@secjs/exceptions'
13+
import { InternalServerException } from '@secjs/exceptions'
1414
import { DriverContract } from '../Contracts/DriverContract'
1515

1616
export class S3Driver implements DriverContract {
@@ -55,7 +55,8 @@ export class S3Driver implements DriverContract {
5555
Body: content,
5656
}
5757

58-
if (await this.exists(filePath)) throw new InternalServerException(`File ${filePath} already exists`)
58+
if (await this.exists(filePath))
59+
throw new InternalServerException(`File ${filePath} already exists`)
5960

6061
await this.s3Client.upload(params).promise()
6162
}
@@ -148,10 +149,11 @@ export class S3Driver implements DriverContract {
148149
Bucket: this._bucket,
149150
Key: filePath,
150151
// 2 weeks
151-
Expires: 121e+6,
152+
Expires: 121e6,
152153
}
153154

154-
if (await this.missing(filePath)) throw new InternalServerException(`File ${filePath} does not exist`)
155+
if (await this.missing(filePath))
156+
throw new InternalServerException(`File ${filePath} does not exist`)
155157

156158
return this.s3Client.getSignedUrlPromise('getObject', params)
157159
}
@@ -170,7 +172,8 @@ export class S3Driver implements DriverContract {
170172
Expires: time / 1000,
171173
}
172174

173-
if (await this.missing(filePath)) throw new InternalServerException(`File ${filePath} does not exist`)
175+
if (await this.missing(filePath))
176+
throw new InternalServerException(`File ${filePath} does not exist`)
174177

175178
return this.s3Client.getSignedUrlPromise('getObject', params)
176179
}
@@ -188,7 +191,8 @@ export class S3Driver implements DriverContract {
188191
}
189192

190193
if (!force) {
191-
if (await this.missing(filePath)) throw new InternalServerException(`File ${filePath} does not exist`)
194+
if (await this.missing(filePath))
195+
throw new InternalServerException(`File ${filePath} does not exist`)
192196
}
193197

194198
await this.s3Client.deleteObject(params).promise()
@@ -204,10 +208,11 @@ export class S3Driver implements DriverContract {
204208
const params = {
205209
Bucket: this._bucket,
206210
CopySource: `/${this._bucket}/${oldFilePath}`,
207-
Key: newFilePath
211+
Key: newFilePath,
208212
}
209213

210-
if (await this.missing(oldFilePath)) throw new InternalServerException(`File ${oldFilePath} does not exist`)
214+
if (await this.missing(oldFilePath))
215+
throw new InternalServerException(`File ${oldFilePath} does not exist`)
211216

212217
await this.s3Client.copyObject(params).promise()
213218
}
@@ -222,12 +227,15 @@ export class S3Driver implements DriverContract {
222227
const params = {
223228
Bucket: this._bucket,
224229
CopySource: `/${this._bucket}/${oldFilePath}`,
225-
Key: newFilePath
230+
Key: newFilePath,
226231
}
227232

228-
if (await this.missing(oldFilePath)) throw new InternalServerException(`File ${oldFilePath} does not exist`)
233+
if (await this.missing(oldFilePath))
234+
throw new InternalServerException(`File ${oldFilePath} does not exist`)
229235

230236
await this.s3Client.copyObject(params).promise()
231-
await this.s3Client.deleteObject({ Bucket: params.Bucket, Key: oldFilePath }).promise()
237+
await this.s3Client
238+
.deleteObject({ Bucket: params.Bucket, Key: oldFilePath })
239+
.promise()
232240
}
233241
}

src/Storage.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ import {
1212
NotImplementedException,
1313
} from '@secjs/exceptions'
1414

15-
import { isAbsolute } from 'path'
15+
import { tmpdir } from 'os'
16+
import { promises } from 'fs'
17+
import { File } from '@secjs/utils'
1618
import { Config } from '@secjs/config'
19+
import { isAbsolute, join } from 'path'
1720
import { Drivers } from './Drivers/Drivers'
1821
import { DriverContract } from './Contracts/DriverContract'
19-
import { File, random } from '@secjs/utils'
20-
import { promises } from 'fs'
21-
import { join } from 'path'
22-
import { tmpdir } from 'os'
23-
import { Env } from '@secjs/env'
2422

2523
export class Storage {
2624
private _tempDriver: DriverContract | null = null
@@ -88,12 +86,20 @@ export class Storage {
8886
this._tempDriver = null
8987
}
9088

91-
async putFile(folder: string, content: any, extension: string): Promise<string> {
89+
async putFile(
90+
folder: string,
91+
content: any,
92+
extension: string,
93+
): Promise<string> {
9294
Storage.verifyAbsolute(folder)
9395

9496
const tmpDir = await promises.mkdtemp(join(tmpdir(), process.env.APP_NAME))
9597

96-
const file = await new File(`${tmpDir}/mock.${extension}`, content, true).create()
98+
const file = await new File(
99+
`${tmpDir}/mock.${extension}`,
100+
content,
101+
true,
102+
).create()
97103

98104
const path = await this._driver.putFile(folder, file)
99105
await file.remove()

0 commit comments

Comments
 (0)