lint: lib/imageRouter

- add typing annotate
- remove unused vars

Signed-off-by: Raccoon <raccoon@hackmd.io>
This commit is contained in:
Raccoon 2021-06-13 15:55:47 +08:00
parent f08097fbbf
commit eaf54c4239
No known key found for this signature in database
GPG Key ID: 06770355DC9ECD38
6 changed files with 11 additions and 11 deletions

View File

@ -6,7 +6,7 @@ import azure from "azure-storage";
import config from "../config";
import {logger} from "../logger";
export function uploadImage(imagePath, callback) {
export function uploadImage(imagePath: string, callback?: (err: Error | null, url ?: string) => void): void {
if (!imagePath || typeof imagePath !== 'string') {
callback(new Error('Image path is missing or wrong'), null)
return
@ -19,11 +19,11 @@ export function uploadImage(imagePath, callback) {
const azureBlobService = azure.createBlobService(config.azure.connectionString)
azureBlobService.createContainerIfNotExists(config.azure.container, {publicAccessLevel: 'blob'}, function (err, result, response) {
azureBlobService.createContainerIfNotExists(config.azure.container, {publicAccessLevel: 'blob'}, function (err) {
if (err) {
callback(new Error(err.message), null)
} else {
azureBlobService.createBlockBlobFromLocalFile(config.azure.container, path.basename(imagePath), imagePath, function (err, result, response) {
azureBlobService.createBlockBlobFromLocalFile(config.azure.container, path.basename(imagePath), imagePath, function (err, result) {
if (err) {
callback(new Error(err.message), null)
} else {

View File

@ -34,7 +34,7 @@ function pickFilename(defaultFilename) {
throw new Error('file exists.')
}
export function uploadImage(imagePath, callback) {
export function uploadImage(imagePath: string, callback: (err: Error | null, url?: string) => void): void {
if (!imagePath || typeof imagePath !== 'string') {
callback(new Error('Image path is missing or wrong'), null)
return

View File

@ -4,7 +4,7 @@ import imgur from "@hackmd/imgur";
import config from "../config";
import {logger} from "../logger";
export function uploadImage(imagePath, callback) {
export function uploadImage(imagePath: string, callback: (err: Error | null, url?: string) => void): void {
if (!imagePath || typeof imagePath !== 'string') {
callback(new Error('Image path is missing or wrong'), null)
return

View File

@ -4,7 +4,7 @@ import config from "../config";
import {logger} from "../logger";
export function uploadImage(imagePath, callback) {
export function uploadImage(imagePath: string, callback: (err: Error | null, url: string) => void): void {
if (!imagePath || typeof imagePath !== 'string') {
callback(new Error('Image path is missing or wrong'), null)
return

View File

@ -15,7 +15,7 @@ const minioClient = new Minio.Client({
secretKey: config.minio.secretKey
})
export function uploadImage(imagePath, callback) {
export function uploadImage(imagePath: string, callback: (err: Error | null, url?: string) => void): void {
if (!imagePath || typeof imagePath !== 'string') {
callback(new Error('Image path is missing or wrong'), null)
return
@ -37,7 +37,7 @@ export function uploadImage(imagePath, callback) {
minioClient.putObject(config.s3bucket, key, buffer, buffer.length, {
ContentType: getImageMimeType(imagePath)
}, function (err, data) {
}, function (err) {
if (err) {
callback(err, null)
return

View File

@ -20,7 +20,7 @@ const s3 = new S3Client({
endpoint: config.s3.endpoint
})
export function uploadImage(imagePath, callback) {
export function uploadImage(imagePath: string, callback: (err: Error | null, url: string) => void): void {
if (!imagePath || typeof imagePath !== 'string') {
callback(new Error('Image path is missing or wrong'), null)
return
@ -44,12 +44,12 @@ export function uploadImage(imagePath, callback) {
}
const mimeType = getImageMimeType(imagePath)
if (mimeType) {
params.ContentType = mimeType
params.ContentType = mimeType as string
}
const command = new PutObjectCommand(params)
s3.send(command).then(data => {
s3.send(command).then(() => {
let s3Endpoint = 's3.amazonaws.com'
if (config.s3.endpoint) {
s3Endpoint = config.s3.endpoint