mirror of
https://github.com/status-im/codimd.git
synced 2025-01-26 02:59:22 +00:00
lint: lib/imageRouter
- add typing annotate - remove unused vars Signed-off-by: Raccoon <raccoon@hackmd.io>
This commit is contained in:
parent
f08097fbbf
commit
eaf54c4239
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user