mirror of
https://github.com/status-im/codimd.git
synced 2025-02-12 05:57:31 +00:00
ts: lib/imageRouter/filesystem.js
Signed-off-by: Raccoon <raccoon@hackmd.io>
This commit is contained in:
parent
8ae51aadef
commit
8222f1fad9
@ -1,17 +1,17 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const crypto = require('crypto')
|
import * as fs from "fs";
|
||||||
const fs = require('fs')
|
import * as path from "path";
|
||||||
const URL = require('url').URL
|
import * as crypto from "crypto";
|
||||||
const path = require('path')
|
import {URL} from "url";
|
||||||
|
|
||||||
const config = require('../config')
|
import * as config from "../config";
|
||||||
const logger = require('../logger')
|
import * as logger from "../logger";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* generate a random filename for uploaded image
|
* generate a random filename for uploaded image
|
||||||
*/
|
*/
|
||||||
function randomFilename () {
|
function randomFilename() {
|
||||||
const buf = crypto.randomBytes(16)
|
const buf = crypto.randomBytes(16)
|
||||||
return `upload_${buf.toString('hex')}`
|
return `upload_${buf.toString('hex')}`
|
||||||
}
|
}
|
||||||
@ -20,7 +20,7 @@ function randomFilename () {
|
|||||||
* pick a filename not exist in filesystem
|
* pick a filename not exist in filesystem
|
||||||
* maximum attempt 5 times
|
* maximum attempt 5 times
|
||||||
*/
|
*/
|
||||||
function pickFilename (defaultFilename) {
|
function pickFilename(defaultFilename) {
|
||||||
let retryCounter = 5
|
let retryCounter = 5
|
||||||
let filename = defaultFilename
|
let filename = defaultFilename
|
||||||
const extname = path.extname(defaultFilename)
|
const extname = path.extname(defaultFilename)
|
||||||
@ -34,7 +34,7 @@ function pickFilename (defaultFilename) {
|
|||||||
throw new Error('file exists.')
|
throw new Error('file exists.')
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.uploadImage = function (imagePath, callback) {
|
export function uploadImage(imagePath, callback) {
|
||||||
if (!imagePath || typeof imagePath !== 'string') {
|
if (!imagePath || typeof imagePath !== 'string') {
|
||||||
callback(new Error('Image path is missing or wrong'), null)
|
callback(new Error('Image path is missing or wrong'), null)
|
||||||
return
|
return
|
Loading…
x
Reference in New Issue
Block a user