Compare commits
4 Commits
b61342b576
...
6256260057
Author | SHA1 | Date |
---|---|---|
decentral1se | 6256260057 | |
decentral1se | f677e27282 | |
decentral1se | c1b25603a8 | |
decentral1se | f66c2e0396 |
|
@ -1,4 +1,5 @@
|
||||||
|
.envrc
|
||||||
.git
|
.git
|
||||||
|
.mypy_cache
|
||||||
.venv
|
.venv
|
||||||
__pycache__
|
__pycache__
|
||||||
.mypy_cache
|
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
*.pyc
|
*.pyc
|
||||||
/__pycache__/
|
/__pycache__/
|
||||||
|
test.py
|
||||||
|
|
32
pubspace.py
32
pubspace.py
|
@ -1,5 +1,6 @@
|
||||||
import logging
|
import logging
|
||||||
from os import environ
|
from os import environ
|
||||||
|
from os.path import basename
|
||||||
|
|
||||||
import owncloud
|
import owncloud
|
||||||
from fastapi import FastAPI, Request
|
from fastapi import FastAPI, Request
|
||||||
|
@ -43,8 +44,11 @@ nextcloud.login(NEXTCLOUD_USER, NEXTCLOUD_APP_PASSWORD)
|
||||||
|
|
||||||
|
|
||||||
def create_share(fpath):
|
def create_share(fpath):
|
||||||
if not nextcloud.is_shared(fpath):
|
fname = basname(fpath)
|
||||||
info = nextcloud.share_file_with_link(fpath)
|
fpaths = nextcloud.list("/", depth="infinity")
|
||||||
|
matching = [f.path for f in fpaths if fname in f.path][0]
|
||||||
|
if not nextcloud.is_shared(matching):
|
||||||
|
info = nextcloud.share_file_with_link(matching)
|
||||||
return info.get_link()
|
return info.get_link()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -53,15 +57,23 @@ def create_share(fpath):
|
||||||
async def home(request: Request):
|
async def home(request: Request):
|
||||||
try:
|
try:
|
||||||
payload = await request.json()
|
payload = await request.json()
|
||||||
request.app.state.log.info(f"Received: {payload}")
|
|
||||||
file = payload["file"]
|
|
||||||
link = create_share(file)
|
|
||||||
if link:
|
|
||||||
request.app.state.log.info(f"Shared {file} on {link}")
|
|
||||||
else:
|
|
||||||
request.app.state.log.info(f"{file} already shared or failure!")
|
|
||||||
except Exception:
|
except Exception:
|
||||||
return {}
|
request.app.state.log.info("Unable to parse request, bailing out")
|
||||||
|
return {"detail": "unknown request"}
|
||||||
|
|
||||||
|
request.app.state.log.info(f"Received: {payload}")
|
||||||
|
|
||||||
|
try:
|
||||||
|
file = payload["rel_path"]
|
||||||
|
link = create_share(file)
|
||||||
|
except Exception:
|
||||||
|
request.app.state.log.info(f"Failed to share {file}"
|
||||||
|
return {"detail": "failed to create share"}
|
||||||
|
|
||||||
|
if link:
|
||||||
|
request.app.state.log.info(f"Shared {file} on {link}")
|
||||||
|
else:
|
||||||
|
request.app.state.log.info(f"{file} already shared or failure!")
|
||||||
|
|
||||||
|
|
||||||
@app.get("/healthz")
|
@app.get("/healthz")
|
||||||
|
|
11
pubspace.sh
11
pubspace.sh
|
@ -1,9 +1,16 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
FILE="$1"
|
set -e
|
||||||
|
|
||||||
|
ACTORS_USER_ID="$1"
|
||||||
|
OWNER_USER_ID="$2"
|
||||||
|
NEXTCLOUD_RELATIVE_PATH="$3"
|
||||||
|
LOCALLY_AVAILABLE_FILE="$4"
|
||||||
|
|
||||||
|
echo "RUNNING: ${FILE}" >> pubspace.log
|
||||||
|
|
||||||
/usr/bin/curl \
|
/usr/bin/curl \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-X GET \
|
-X GET \
|
||||||
-d "{\"file\":\"${FILE}\"}" \
|
-d "{\"actor_id\":\"${ACTORS_USER_ID}\", \"owner_id\":\"${OWNER_USER_ID}\", \"rel_path\":\"${NEXTCLOUD_RELATIVE_PATH}\", \"local_path\":\"${LOCALLY_AVAILABLE_PATH}\"}" \
|
||||||
https://publish.lumbung.space
|
https://publish.lumbung.space
|
||||||
|
|
Reference in New Issue