Compare commits
8 Commits
5b4fe5fc54
...
main
Author | SHA1 | Date | |
---|---|---|---|
1e62814108
|
|||
bc7f51098e
|
|||
6256260057
|
|||
f677e27282
|
|||
c1b25603a8
|
|||
f66c2e0396
|
|||
b61342b576
|
|||
0aa5c1b625
|
@ -1,4 +1,5 @@
|
||||
.envrc
|
||||
.git
|
||||
.mypy_cache
|
||||
.venv
|
||||
__pycache__
|
||||
.mypy_cache
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
*.pyc
|
||||
/__pycache__/
|
||||
test.py
|
||||
|
@ -1,5 +1,11 @@
|
||||
# pubspace
|
||||
|
||||
> **WARNING**: this was an experimental prototype to understand if an
|
||||
> "always-on" intermediary service could facilitate digital publishing
|
||||
> practices in the lumbung.space. We have since moved to the idea of a
|
||||
> slow and not real-time mode of publishing which will happen in another
|
||||
> repository.
|
||||
|
||||
[](https://drone.autonomic.zone/ruangrupa/pubspace)
|
||||
|
||||
A service to facilitate collective digital publishing practices.
|
||||
|
@ -5,10 +5,12 @@ services:
|
||||
app:
|
||||
image: "decentral1se/pubspace:latest"
|
||||
environment:
|
||||
- MASTODON_ACCESS_TOKEN_FILE=/run/secrets/access_token
|
||||
- NEXTCLOUD_APP_PASSWORD_FILE=/run/secrets/app_password
|
||||
- MASTODON_API_BASE_URL
|
||||
- APP_LOG_LEVEL
|
||||
- MASTODON_ACCESS_TOKEN_FILE=/run/secrets/access_token
|
||||
- MASTODON_API_BASE_URL
|
||||
- NEXTCLOUD_API_BASE_URL
|
||||
- NEXTCLOUD_APP_PASSWORD_FILE=/run/secrets/app_password
|
||||
- NEXTCLOUD_USER
|
||||
secrets:
|
||||
- access_token
|
||||
- app_password
|
||||
|
2
makefile
2
makefile
@ -12,5 +12,5 @@ run:
|
||||
build:
|
||||
@docker build -t decentral1se/pubspace .
|
||||
|
||||
push:
|
||||
push: build
|
||||
@docker push decentral1se/pubspace
|
||||
|
31
pubspace.py
31
pubspace.py
@ -1,5 +1,6 @@
|
||||
import logging
|
||||
from os import environ
|
||||
from os.path import basename
|
||||
|
||||
import owncloud
|
||||
from fastapi import FastAPI, Request
|
||||
@ -43,8 +44,11 @@ nextcloud.login(NEXTCLOUD_USER, NEXTCLOUD_APP_PASSWORD)
|
||||
|
||||
|
||||
def create_share(fpath):
|
||||
if not nextcloud.is_shared(fpath):
|
||||
info = nextcloud.share_file_with_link(fpath)
|
||||
fname = basname(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 None
|
||||
|
||||
@ -53,14 +57,23 @@ def create_share(fpath):
|
||||
async def home(request: Request):
|
||||
try:
|
||||
payload = await request.json()
|
||||
file = payload["file"]
|
||||
link = create_share(file)
|
||||
if link:
|
||||
app.state.log(f"Shared {file} on {link}")
|
||||
else:
|
||||
app.state.log(f"{file} has already been shared!")
|
||||
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")
|
||||
|
@ -1,9 +1,14 @@
|
||||
#!/bin/bash
|
||||
|
||||
FILE="$1"
|
||||
set -e
|
||||
|
||||
ACTORS_USER_ID="$1"
|
||||
OWNER_USER_ID="$2"
|
||||
NEXTCLOUD_RELATIVE_PATH="$3"
|
||||
LOCALLY_AVAILABLE_FILE="$4"
|
||||
|
||||
/usr/bin/curl \
|
||||
-H "Content-Type: application/json" \
|
||||
-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
|
||||
|
Reference in New Issue
Block a user