-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (56 loc) · 2.19 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* eslint-disable no-warning-comments */
const { React, getModule } = require('powercord/webpack');
const { Plugin } = require('powercord/entities');
const { inject, uninject } = require('powercord/injector');
const { findInReactTree } = require('powercord/util');
const Settings = require('./ui/Settings.jsx');
const Uploader = require('./Uploader');
/**
* Upload files to the cloud
* @link https://github.com/RazerMoon/uploadToCloud
* @license MIT
* @extends Plugin
*/
module.exports = class UploadToCloud extends Plugin {
startPlugin () {
powercord.api.settings.registerSettings(this.entityID, {
category: this.entityID,
label: 'Upload to Cloud',
render: Settings
});
this.patchAttachMenu();
}
async handleClick () {
try {
const [ fileHandle ] = await window.showOpenFilePicker();
const file = await fileHandle.getFile();
const uploader = new Uploader(this.settings.get('provider', 'UFile.io'), this.settings.get('chunkSize', 5e+6));
uploader.initUpload(file);
} catch (error) {
this.log('Aborted file pick');
}
}
async patchAttachMenu () {
const Menu = await getModule((m) => (m.__powercordOriginal_default || m.default)?.displayName === 'Menu');
const mod = await getModule((m) => (m.__powercordOriginal_default || m.default)?.displayName === 'ChannelAttachMenu');
inject('uploadtocloud-attachmenu-patch', mod, 'default', (_req, res) => {
if (!res) {
return res;
}
const hasUploadButton = findInReactTree(res.children, child => child.props && child.props.id === 'upload');
if (!hasUploadButton) {
const uploadButton = React.createElement(Menu.MenuItem, {
id: 'upload',
label: 'Upload to Cloud',
action: () => this.handleClick()
});
res.props.children.splice(res.props.children.length - 1, 0, [ React.createElement(Menu.MenuGroup, {}, uploadButton), React.createElement(Menu.MenuSeparator) ]);
}
return res;
});
}
pluginWillUnload () {
uninject('uploadtocloud-attachmenu-patch');
powercord.api.settings.unregisterSettings(this.entityID);
}
};