This commit is contained in:
Jan 2020-07-16 18:42:30 +02:00
commit ccb306f325
8 changed files with 1753 additions and 0 deletions

5
.env.example Normal file
View file

@ -0,0 +1,5 @@
WEBDAV_URL=https://your.webdav.host
WEBDAV_USER=user
WEBDAV_PW=pass
WEBFRAME_PATH=/path/to/imgs/
PORT=3000

124
.gitignore vendored Normal file
View file

@ -0,0 +1,124 @@
node_modules
*-bkp
dist
dist-bkp
.env
files/*
# https://github.com/github/gitignore/blob/master/Node.gitignore
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

5
README.md Normal file
View file

@ -0,0 +1,5 @@
# Webframe
A simple digital picture frame as a website.
Inspired by TeleFrame https://github.com/LukeSkywalker92/TeleFrame

50
db.json Normal file
View file

@ -0,0 +1,50 @@
{
"files": [
{
"filename": "/Bilder/WebFrame/photo_2020-06-17_22-54-30_16-9.png",
"basename": "photo_2020-06-17_22-54-30_16-9.png",
"lastmod": "Thu, 18 Jun 2020 08:17:38 GMT",
"size": 1278620,
"type": "file",
"etag": ""a4b835902fbf096db14a4d959191eac0"",
"mime": "image/png"
},
{
"filename": "/Bilder/WebFrame/photo_2020-06-17_22-54-43_16-9.png",
"basename": "photo_2020-06-17_22-54-43_16-9.png",
"lastmod": "Thu, 18 Jun 2020 08:17:38 GMT",
"size": 1708544,
"type": "file",
"etag": ""19389a5cd0b75b7dbd39b84bb4296dbe"",
"mime": "image/png"
},
{
"filename": "/Bilder/WebFrame/photo_2020-06-17_22-54-46_16-9.png",
"basename": "photo_2020-06-17_22-54-46_16-9.png",
"lastmod": "Thu, 18 Jun 2020 08:17:40 GMT",
"size": 1485855,
"type": "file",
"etag": ""e97d6b75171dc770661d8b133f1f3b3d"",
"mime": "image/png"
},
{
"filename": "/Bilder/WebFrame/photo_2020-07-16_17-45-44.jpg",
"basename": "photo_2020-07-16_17-45-44.jpg",
"lastmod": "Thu, 16 Jul 2020 15:45:49 GMT",
"size": 163872,
"type": "file",
"etag": ""55f39d92914769f86d821ab164aac1cf"",
"mime": "image/jpeg"
},
{
"filename": "/Bilder/WebFrame/video_2020-07-16_17-46-45.mp4",
"basename": "video_2020-07-16_17-46-45.mp4",
"lastmod": "Thu, 16 Jul 2020 15:46:47 GMT",
"size": 1305164,
"type": "file",
"etag": ""add81c6ec9e5b37ba35c1930a6740a28"",
"mime": "video/mp4"
}
],
"count": 5
}

57
index.js Normal file
View file

@ -0,0 +1,57 @@
require('dotenv').config();
const { createClient } = require('webdav');
const fs = require('fs');
const path = require('path');
// init db
const low = require('lowdb');
const FileSync = require('lowdb/adapters/FileSync');
const adapter = new FileSync('db.json');
const db = low(adapter);
// db.defaults({ files: [], count: 0}).write();
// create webdav-client
const client = createClient(
process.env.WEBDAV_URL,
{
username: process.env.WEBDAV_USER,
password: process.env.WEBDAV_PW
}
);
async function listDir(dir = process.env.WEBFRAME_PATH) {
const directoryItems = await client.getDirectoryContents(dir);
return directoryItems;
}
function dlFile(file, dir = process.env.WEBFRAME_PATH) {
return client.createReadStream(dir+'/'+file).pipe(fs.createWriteStream('./files/'+file));
}
client.exists(process.env.WEBFRAME_PATH).then(async data => {
if (data) {
const list = await listDir(process.env.WEBFRAME_PATH);
list.forEach(file => {
// if (!fs.existsSync('./files/'+file.basename)) {
const inDb = db.get('files').find({ basename: file.basename }).value() !== undefined ? true : false;
if (!inDb) {
dlFile(file.basename);
db.get('files').push(file).write();
db.update('count', n => n + 1).write();
}
});
}
});
// webserver
const express = require('express');
const app = express();
app.use('/files', express.static(path.join(__dirname, 'files')));
app.get('/api/files', (req, res) => {
res.json(db.get('files').value());
});
app.use('*', express.static(path.join(__dirname, 'public')));
app.listen(process.env.PORT, () => console.log(`Example app listening at http://localhost:${process.env.PORT}`));

1491
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

20
package.json Normal file
View file

@ -0,0 +1,20 @@
{
"name": "webframe",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT",
"dependencies": {
"dotenv": "^8.2.0",
"express": "^4.17.1",
"lowdb": "^1.0.0",
"webdav": "^3.3.0"
},
"devDependencies": {
"nodemon": "^2.0.4"
}
}

1
public/index.html Normal file
View file

@ -0,0 +1 @@
index