mirror of https://github.com/VueTubeApp/VueTube
feat: ✨ plugins pt.2 | im done for today
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa fuck
This commit is contained in:
parent
7aac426ec7
commit
bf7d79e164
|
@ -2,8 +2,8 @@
|
|||
<div>
|
||||
|
||||
<div style="margin: 1em;">
|
||||
<v-btn style="width: 100%;" class="primary" @click="pickFile()">Load Plugin</v-btn>
|
||||
<input type="file" id="filePicker" accept=".js" />
|
||||
<v-btn style="width: 100%;" class="primary text-none" @click="pickFile()"><v-icon style="margin-right: 0.5em;">mdi-sd</v-icon> Install from storage</v-btn>
|
||||
<input type="file" id="filePicker" accept="js" />
|
||||
</div>
|
||||
|
||||
<center v-if="plugins.length == 0" style="margin-top: 2em;">
|
||||
|
@ -72,14 +72,25 @@ export default {
|
|||
async mounted() {
|
||||
//this.plugins = await this.$tppl.list;
|
||||
|
||||
document.getElementById('filePicker').onchange = function() {
|
||||
const vm = this;
|
||||
document.getElementById('filePicker').onchange = async function() {
|
||||
const file = document.getElementById("filePicker").files[0];
|
||||
|
||||
const contents = await vm.readFileContent(file);
|
||||
await vm.$tppl.addPlugin(contents);
|
||||
};
|
||||
|
||||
|
||||
},
|
||||
methods: {
|
||||
readFileContent(file) {
|
||||
const reader = new FileReader()
|
||||
return new Promise((resolve, reject) => {
|
||||
reader.onload = event => resolve(event.target.result)
|
||||
reader.onerror = error => reject(error)
|
||||
reader.readAsText(file)
|
||||
})
|
||||
},
|
||||
|
||||
pickFile() {
|
||||
document.getElementById("filePicker").click();
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ const ytApiVal = {
|
|||
};
|
||||
|
||||
const filesystem = {
|
||||
plugins: "vuetube/plugins"
|
||||
plugins: "plugins"
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
|
|
@ -5,16 +5,8 @@ import { fs } from './constants';
|
|||
//--- Set Up App Directory ---//
|
||||
const APP_DIRECTORY = Directory.Data;
|
||||
|
||||
|
||||
//--- Ensure Plugins Folder ---//
|
||||
const ensureStructure = new Promise(async (resolve, reject) => {
|
||||
/*
|
||||
const perms = await Filesystem.checkPermissions();
|
||||
if (perms.publicStorage !== "granted") {
|
||||
perms = await Filesystem.requestPermissions();
|
||||
}
|
||||
// Legacy shit that isnt supported on android 10+ */
|
||||
|
||||
//--- Ensure Plugins Folder ---//
|
||||
try {
|
||||
await Filesystem.mkdir({
|
||||
directory: APP_DIRECTORY, recursive: true,
|
||||
|
@ -22,40 +14,38 @@ const ensureStructure = new Promise(async (resolve, reject) => {
|
|||
});
|
||||
} catch (e) { /* Exists */ }
|
||||
|
||||
perms
|
||||
? resolve(true)
|
||||
: reject(false)
|
||||
|
||||
resolve();
|
||||
})
|
||||
|
||||
|
||||
const module = {
|
||||
|
||||
|
||||
//--- List Plugins ---//
|
||||
list: new Promise(async (resolve, reject) => {
|
||||
|
||||
if (await !ensureStructure) reject("Invalid Structure");
|
||||
await ensureStructure();
|
||||
|
||||
const plugins = await Filesystem.readdir({
|
||||
path: fs.plugins,
|
||||
directory: APP_DIRECTORY
|
||||
});
|
||||
}).catch(err => { reject(err) })
|
||||
resolve(plugins);
|
||||
|
||||
}),
|
||||
|
||||
debug(path) { return new Promise(async (resolve, reject) => {
|
||||
addPlugin(content) {
|
||||
await ensureStructure();
|
||||
new Promise(async (resolve, reject) => {
|
||||
const fileName = require("./utils").getCpn(); // Im not sure what this is actually meant for but im using it as a random string generator
|
||||
console.log("Saving Plugin As"+ fileName)
|
||||
await Filesystem.writeFile({
|
||||
path: fs.plugins+"/"+fileName+".js",
|
||||
directory: APP_DIRECTORY,
|
||||
data: content,
|
||||
encoding: Encoding.UTF8,
|
||||
});
|
||||
|
||||
if (await !ensureStructure) reject("Invalid Structure");
|
||||
|
||||
const plugins = await Filesystem.readdir({
|
||||
path: path,
|
||||
directory: APP_DIRECTORY
|
||||
});
|
||||
resolve(plugins);
|
||||
|
||||
})}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue