mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-21 16:20:46 +08:00
✨ Feature(server): add http server for uploading images by a http request
port 37766
This commit is contained in:
6
src/main/utils/busApi/constants.ts
Normal file
6
src/main/utils/busApi/constants.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export const GET_SETTING_WINDOW = 'GET_SETTING_WINDOW'
|
||||
export const GET_MINI_WINDOW = 'GET_SETTING_WINDOW'
|
||||
export const UPLOAD_WITH_FILES = 'UPLOAD_WITH_FILES'
|
||||
export const UPLOAD_WITH_FILES_RESPONSE = 'UPLOAD_WITH_FILES_RESPONSE'
|
||||
export const UPLOAD_WITH_CLIPBOARD_FILES = 'UPLOAD_WITH_CLIPBOARD_FILES'
|
||||
export const UPLOAD_WITH_CLIPBOARD_FILES_RESPONSE = 'UPLOAD_WITH_CLIPBOARD_FILES_RESPONSE'
|
||||
49
src/main/utils/busApi/index.ts
Normal file
49
src/main/utils/busApi/index.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import bus from '../eventBus'
|
||||
import {
|
||||
UPLOAD_WITH_FILES,
|
||||
UPLOAD_WITH_FILES_RESPONSE,
|
||||
UPLOAD_WITH_CLIPBOARD_FILES,
|
||||
UPLOAD_WITH_CLIPBOARD_FILES_RESPONSE
|
||||
} from './constants'
|
||||
|
||||
export const uploadWithClipboardFiles = (): Promise<{
|
||||
success: boolean,
|
||||
result?: string[]
|
||||
}> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
bus.emit(UPLOAD_WITH_CLIPBOARD_FILES)
|
||||
bus.once(UPLOAD_WITH_CLIPBOARD_FILES_RESPONSE, (result: string) => {
|
||||
if (result) {
|
||||
return resolve({
|
||||
success: true,
|
||||
result: [result]
|
||||
})
|
||||
} else {
|
||||
return resolve({
|
||||
success: false
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const uploadWithFiles = (pathList: IFileWithPath[]): Promise<{
|
||||
success: boolean,
|
||||
result?: string[]
|
||||
}> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
bus.emit(UPLOAD_WITH_FILES, pathList)
|
||||
bus.once(UPLOAD_WITH_FILES_RESPONSE, (result: string[]) => {
|
||||
if (result.length) {
|
||||
return resolve({
|
||||
success: true,
|
||||
result
|
||||
})
|
||||
} else {
|
||||
return resolve({
|
||||
success: false
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user