Browse Source

Server

master
marcoschmickler 5 years ago
parent
commit
acb9842981
  1. 12
      kplayer.xcodeproj/project.pbxproj
  2. 171
      kplayer/server/kplayer.js

12
kplayer.xcodeproj/project.pbxproj

@ -24,6 +24,7 @@
1C73671FC2CCCACAA2FFC153 /* ThumbnailCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C736EA15A11AF7D57F85824 /* ThumbnailCache.swift */; }; 1C73671FC2CCCACAA2FFC153 /* ThumbnailCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C736EA15A11AF7D57F85824 /* ThumbnailCache.swift */; };
1C73673F39A34C3275D0230A /* BMPlayerClearityChooseButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C736DFBD072763248412F74 /* BMPlayerClearityChooseButton.swift */; }; 1C73673F39A34C3275D0230A /* BMPlayerClearityChooseButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C736DFBD072763248412F74 /* BMPlayerClearityChooseButton.swift */; };
1C73675C34BE0990D44570BE /* ItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C736253AB7A95EA41B605B7 /* ItemModel.swift */; }; 1C73675C34BE0990D44570BE /* ItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C736253AB7A95EA41B605B7 /* ItemModel.swift */; };
1C736771C503FB0D52AEB8F7 /* kplayer.js in Sources */ = {isa = PBXBuildFile; fileRef = 1C73625012D50E457D18A785 /* kplayer.js */; };
1C7367AF39961D2BA72480ED /* DataLoadOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C736F9338CE36708244D42A /* DataLoadOperation.swift */; }; 1C7367AF39961D2BA72480ED /* DataLoadOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C736F9338CE36708244D42A /* DataLoadOperation.swift */; };
1C7367FA10AE13598FDDE865 /* BMPlayerProtocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C7365F45D765A218FFC100F /* BMPlayerProtocols.swift */; }; 1C7367FA10AE13598FDDE865 /* BMPlayerProtocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C7365F45D765A218FFC100F /* BMPlayerProtocols.swift */; };
1C736821D6DF2237A3EABCC1 /* ViewControllerExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C73648CEC974A2500172064 /* ViewControllerExtensions.swift */; }; 1C736821D6DF2237A3EABCC1 /* ViewControllerExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C73648CEC974A2500172064 /* ViewControllerExtensions.swift */; };
@ -79,6 +80,7 @@
1C73610B997EBA367C806C1B /* BMPlayerCompositionResourceDefinition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BMPlayerCompositionResourceDefinition.swift; sourceTree = "<group>"; }; 1C73610B997EBA367C806C1B /* BMPlayerCompositionResourceDefinition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BMPlayerCompositionResourceDefinition.swift; sourceTree = "<group>"; };
1C73611D226B48C24DB37535 /* MasterViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MasterViewController.swift; sourceTree = "<group>"; }; 1C73611D226B48C24DB37535 /* MasterViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MasterViewController.swift; sourceTree = "<group>"; };
1C73620D01687FB4F1811C5C /* NetworkHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkHelper.swift; sourceTree = "<group>"; }; 1C73620D01687FB4F1811C5C /* NetworkHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkHelper.swift; sourceTree = "<group>"; };
1C73625012D50E457D18A785 /* kplayer.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = kplayer.js; sourceTree = "<group>"; };
1C736253AB7A95EA41B605B7 /* ItemModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ItemModel.swift; sourceTree = "<group>"; }; 1C736253AB7A95EA41B605B7 /* ItemModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ItemModel.swift; sourceTree = "<group>"; };
1C736260E748CF136FF37EA7 /* UploadOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UploadOperation.swift; sourceTree = "<group>"; }; 1C736260E748CF136FF37EA7 /* UploadOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UploadOperation.swift; sourceTree = "<group>"; };
1C73631C96E6C860833052CA /* ItemType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ItemType.swift; sourceTree = "<group>"; }; 1C73631C96E6C860833052CA /* ItemType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ItemType.swift; sourceTree = "<group>"; };
@ -158,6 +160,14 @@
path = detail; path = detail;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
1C73633B55AC5378053BDCE2 /* server */ = {
isa = PBXGroup;
children = (
1C73625012D50E457D18A785 /* kplayer.js */,
);
path = server;
sourceTree = "<group>";
};
1C7363B608460DED4F522D1C /* photo */ = { 1C7363B608460DED4F522D1C /* photo */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@ -282,6 +292,7 @@
1C7364808E72BFA7575E75E1 /* master */, 1C7364808E72BFA7575E75E1 /* master */,
1C7363B608460DED4F522D1C /* photo */, 1C7363B608460DED4F522D1C /* photo */,
1C736F3946A38499113D351A /* video */, 1C736F3946A38499113D351A /* video */,
1C73633B55AC5378053BDCE2 /* server */,
); );
path = kplayer; path = kplayer;
sourceTree = "<group>"; sourceTree = "<group>";
@ -514,6 +525,7 @@
1C736A06A2AD75B8C14EEBBE /* HtmlParser.swift in Sources */, 1C736A06A2AD75B8C14EEBBE /* HtmlParser.swift in Sources */,
1C736667B944A494666AEEAE /* Downloader.swift in Sources */, 1C736667B944A494666AEEAE /* Downloader.swift in Sources */,
1C736048BFA120F5C7D36874 /* readme.md in Sources */, 1C736048BFA120F5C7D36874 /* readme.md in Sources */,
1C736771C503FB0D52AEB8F7 /* kplayer.js in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };

171
kplayer/server/kplayer.js

@ -0,0 +1,171 @@
var express = require('express');
var fs = require("fs");
var path = require("path");
const { exec } = require('child_process');
const bodyParser= require('body-parser')
const multer = require('multer');
var app = express();
app.use(bodyParser.urlencoded({extended: true}))
app.get('/', function(req, res) {
res.json({ message: 'WELCOME' });
});
function isVideoFolder(address) {
return getFiles(address).filter(dirent => dirent.name.endsWith(".mp4")).length > 0
}
function hasPics(address) {
return getFiles(address).filter(dirent => dirent.name.endsWith(".jpg")).length > 0
}
function getFiles(address) {
return fs.readdirSync(address, {withFileTypes: true})
// .filter(dirent => dirent.isDirectory())
// .map(dirent => dirent.name);
}
app.get('/listdirs/*', function (req, res) {
var address = req.path.substr(9)
console.log("listdirs " + address);
if (!req.path.startsWith("/listdirs/srv/samba/ren/")) {
res.end("Access denied")
return
}
var files = getFiles(address)
var leaf = true
var result = [];
files.forEach(function(file){
var filename = file.name
var filetype = "folder"
var pics = false
if ((file.isDirectory() || file.isSymbolicLink()) && !filename.startsWith(".")) {
var folders = getFiles(address + "/" + filename)
if (folders.filter(dirent => dirent.name.endsWith(".mp4")).length > 0) {
filetype = "video"
}
else if (folders.filter(dirent => dirent.name.endsWith(".html")).length > 0) {
filetype = "web"
}
// else if (folders.filter(dirent => dirent.name.endsWith(".jpg")).length > 0) {
else {
folders.forEach(function (f) {
if (f.isDirectory()) {
if (hasPics(address + "/" + filename + "/" + f.name)) {
filetype = "pictures"
}
}
})
}
console.log(filename)
result.push([filename, filetype])
}
})
res.end(JSON.stringify(result))
})
var storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, 'uploads')
},
filename: function (req, file, cb) {
cb(null, file.fieldname + '-' + Date.now())
}
})
var upload = multer({ storage: storage })
app.get('/alive', function (req, res) {
let date = new Date()
var d = date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() + "\n"
console.log(d)
var p = '/mnt/archive/ren/alive.txt'
fs.writeFileSync(p, d, { mode: 0o755 });
// fs.unlinkSync(p);
p = '/mnt/backup/ren/alive.txt'
fs.writeFileSync(p, d, { mode: 0o755 });
// fs.unlinkSync(p);
p = '/mnt/work/ren/alive.txt'
fs.writeFileSync(p, d, { mode: 0o755 });
// fs.unlinkSync(p);
res.send("ok")
})
app.get('/ffmpeg', function (req, res) {
var p = req.query.url
var n = "/srv/samba/ren/webdl/" + req.query.name
var cmd = 'ffmpeg -i "'+p+'" -codec copy "'+n+'"'
console.log(cmd)
exec(cmd, (err, stdout, stderr) => {
if (err) {
console.log(err)
// node couldn't execute the command
return;
}
// the *entire* stdout and stderr (buffered)
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
});
res.send(p)
})
app.get('/deleteThumb/*', function (req, res) {
if (req.path.startsWith("/deleteThumb/srv/samba/ren/thumb/")) {
var p = req.path.substr(12)
fs.unlinkSync(p)
console.log("removed " + p)
}
res.send("ok")
})
//createDirectories(pathname) {}
app.post('/upload', upload.any() , (req, res, next) => {
// const file = req.file
var files = req.files;
var newPath = req.body.name
console.log(newPath)
if(files){
files.forEach(function(file){
//Move file to the deployment folder.
const __dirname = path.resolve();
var pathname = newPath.substring(0, newPath.lastIndexOf('/'))
console.log(pathname);
fs.mkdir(path.resolve(__dirname, pathname), { recursive: true }, e => {
if (e) {
console.error(e);
} else {
console.log(pathname);
}
});
// createDirectories(newPath)
fs.renameSync(file.path, newPath);
console.log(file.path);
});
}
res.send("ok")
})
var server = app.listen(8081, function () {
var host = server.address().address
var port = server.address().port
console.log("Server listening at http://%s:%s", host, port)
})
Loading…
Cancel
Save