Files
electron-egg/electron/service/example.js
2022-11-17 15:32:10 +08:00

68 lines
1.4 KiB
JavaScript
Raw 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').Service;
/**
* 示例服务
* @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') {
this.app.logger.info('[ExampleService] [uploadFileToSMMS]: info result:%j', result);
}
if (result.code !== 'success') {
this.app.logger.error('[ExampleService] [uploadFileToSMMS]: res error result:%j', result);
}
return result;
} catch (e) {
this.app.logger.error('[ExampleService] [uploadFileToSMMS]: ERROR ', e);
}
return res;
}
}
ExampleService.toString = () => '[class ExampleService]';
module.exports = ExampleService;