Files
electron-egg/electron/service/example.js
哆啦好梦 948084cbc1 remove module
2023-03-06 10:29:00 +08:00

69 lines
1.4 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use strict';
const { Service } = require('ee-core');
const Log = require('ee-core/log');
/**
* 示例服务
* @class
*/
class ExampleService extends Service {
constructor(ctx) {
super(ctx);
}
/**
* test
*/
async test (args) {
let obj = {
status:'ok',
params: args
}
return obj;
}
/**
* 上传到smms
*/
async uploadFileToSMMS(tmpFile) {
const res = {
code: 1000,
message: 'unknown error',
};
try {
const headersObj = {
'Content-Type': 'multipart/form-data',
'Authorization': 'aaaaaaaaaaaaa' // 请修改这个token用你自己的账号token
};
const url = 'https://sm.ms/api/v2/upload';
const response = await this.app.curl(url, {
method: 'POST',
headers: headersObj,
files: {
smfile: tmpFile,
},
dataType: 'json',
timeout: 15000,
});
const result = response.data;
if (this.app.config.env === 'local') {
Log.info('[ExampleService] [uploadFileToSMMS]: info result:%j', result);
}
if (result.code !== 'success') {
Log.error('[ExampleService] [uploadFileToSMMS]: res error result:%j', result);
}
return result;
} catch (e) {
Log.error('[ExampleService] [uploadFileToSMMS]: ERROR ', e);
}
return res;
}
}
ExampleService.toString = () => '[class ExampleService]';
module.exports = ExampleService;