mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-16 23:30:41 +09:00
Added search functionality to mod manager #59
This commit is contained in:
1 parent
88ff90262d
commit
2fd47434bb
6 files changed
+71
-12
No files matched your search
Whitespace-only changes.
Whitespace-only changes.
@@ -1,8 +1,10 @@
|
||||
const rightpad = require("right-pad");
|
||||
const asTable = require("as-table").configure({delimiter: ' | '});
|
||||
const moment = require("moment");
|
||||
|
||||
const factorioAPI = require("node-factorio-api");
|
||||
const fileOps = require("./../fileOps.js");
|
||||
const config = require("./../../config");
|
||||
|
||||
const instances = fileOps.getDirectoriesSync("./instances/");
|
||||
|
||||
@@ -11,8 +13,8 @@ module.exports.listMods = function(instance){
|
||||
factorioAPI.init(false, 'instances/'+instance+'/mods', 'instances/'+instance+'/saves', '0.15.37');
|
||||
console.log("Authenticating to factorio.com...")
|
||||
factorioAPI.authenticate({
|
||||
username: 'Danielv123',
|
||||
token: '53faebce0a608b1195f01dcfd95ee1',
|
||||
username: config.username,
|
||||
token: config.token,
|
||||
require_ownership: false
|
||||
}).then(token => {
|
||||
console.log("Currently installed:");
|
||||
@@ -40,8 +42,8 @@ module.exports.listMods = function(instance){
|
||||
factorioAPI.init(false, 'sharedMods/', '', '0.15.37');
|
||||
console.log("Authenticating to factorio.com...")
|
||||
factorioAPI.authenticate({
|
||||
username: 'Danielv123',
|
||||
token: '53faebce0a608b1195f01dcfd95ee1',
|
||||
username: config.username,
|
||||
token: config.token,
|
||||
require_ownership: false
|
||||
}).then(() => {
|
||||
factorioAPI.getInstalledMods().then(mods => {
|
||||
@@ -57,6 +59,31 @@ module.exports.listMods = function(instance){
|
||||
console.log(JSON.parse(res.getBody()))
|
||||
*/
|
||||
}
|
||||
module.exports.findMods = function(searchTerm){
|
||||
factorioAPI.init(false);
|
||||
console.log("Authenticating to factorio.com...")
|
||||
factorioAPI.authenticate({
|
||||
username: config.username,
|
||||
token: config.token,
|
||||
require_ownership: false
|
||||
}).then(token => {
|
||||
factorioAPI.searchMods(
|
||||
{q: searchTerm, order: 'top', page_size: 20}
|
||||
).then(body => {
|
||||
let mods = body.results;
|
||||
console.log(asTable(mods.map(mod => {
|
||||
return {
|
||||
title:mod.title,
|
||||
name:mod.name,
|
||||
downloads:mod.downloads_count,
|
||||
updated: moment(mod.updated_at).format("DD.MM.YY"),
|
||||
owner:mod.owner,
|
||||
//license: mod.license_name,
|
||||
}
|
||||
})))
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
// 'https://api.github.com/repos/Danielv123/factorioClusterioMod/releases'
|
||||
module.exports.downloadFromGitURL = function(url){
|
||||
@@ -68,8 +95,8 @@ module.exports.downloadFromGitURL = function(url){
|
||||
console.log(JSON.parse(res.getBody()))
|
||||
if(downloadUrl) {
|
||||
console.log(downloadUrl);
|
||||
var file = fs.createWriteStream("sharedMods/"+name);
|
||||
var request = https.get(downloadUrl, function(response) {
|
||||
let file = fs.createWriteStream("sharedMods/"+name);
|
||||
https.get(downloadUrl, function(response) {
|
||||
response.pipe(file);
|
||||
console.log("Downloaded "+name);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user