Compare commits
2 Commits
d77cdb5243
...
5b4fe5fc54
Author | SHA1 | Date |
---|---|---|
decentral1se | 5b4fe5fc54 | |
decentral1se | f84c65fab8 |
|
@ -2,9 +2,13 @@
|
||||||
export MASTODON_ACCESS_TOKEN=foobar
|
export MASTODON_ACCESS_TOKEN=foobar
|
||||||
export MASTODON_API_BASE_URL=social.lumbung.space
|
export MASTODON_API_BASE_URL=social.lumbung.space
|
||||||
export APP_LOG_LEVEL=info
|
export APP_LOG_LEVEL=info
|
||||||
|
export NEXTCLOUD_API_BASE_URL=cloud.lumbung.space
|
||||||
|
export NEXTCLOUD_USER=decentral1se
|
||||||
|
export NEXTCLOUD_APP_PASSWORD=barfoo
|
||||||
|
|
||||||
# Deployment
|
# Deployment
|
||||||
export STACK_NAME=publish_lumbung_space
|
export STACK_NAME=publish_lumbung_space
|
||||||
export DOMAIN=publish.lumbung.space
|
export DOMAIN=publish.lumbung.space
|
||||||
export ENTRYPOINT_CONF_VERSION=v1
|
export ENTRYPOINT_CONF_VERSION=v1
|
||||||
export SECRET_MASTODON_ACCESS_TOKEN=v1
|
export SECRET_MASTODON_ACCESS_TOKEN=v1
|
||||||
|
export SECRET_NEXTCLOUD_APP_PASSWORD=v1
|
||||||
|
|
|
@ -44,6 +44,7 @@ to generate a share for that file. The Nextcloud crontab runs the script.
|
||||||
|
|
||||||
```
|
```
|
||||||
$ printf $YOURMASTODONACCESSTOKEN | docker secret create publish_lumbung_space_access_token_v1 -
|
$ printf $YOURMASTODONACCESSTOKEN | docker secret create publish_lumbung_space_access_token_v1 -
|
||||||
|
$ printf $YOURNEXTCLOUDAPPPASSWORD | docker secret create publish_lumbung_space_app_password_v1 -
|
||||||
$ cp .env.sample .env # and update the values to match the environment
|
$ cp .env.sample .env # and update the values to match the environment
|
||||||
$ set -a && source .env && set +a
|
$ set -a && source .env && set +a
|
||||||
$ docker stack deploy -c compose.yml publish_lumbung_space
|
$ docker stack deploy -c compose.yml publish_lumbung_space
|
||||||
|
|
|
@ -6,10 +6,12 @@ services:
|
||||||
image: "decentral1se/pubspace:latest"
|
image: "decentral1se/pubspace:latest"
|
||||||
environment:
|
environment:
|
||||||
- MASTODON_ACCESS_TOKEN_FILE=/run/secrets/access_token
|
- MASTODON_ACCESS_TOKEN_FILE=/run/secrets/access_token
|
||||||
|
- NEXTCLOUD_APP_PASSWORD_FILE=/run/secrets/app_password
|
||||||
- MASTODON_API_BASE_URL
|
- MASTODON_API_BASE_URL
|
||||||
- APP_LOG_LEVEL
|
- APP_LOG_LEVEL
|
||||||
secrets:
|
secrets:
|
||||||
- access_token
|
- access_token
|
||||||
|
- app_password
|
||||||
networks:
|
networks:
|
||||||
- proxy
|
- proxy
|
||||||
configs:
|
configs:
|
||||||
|
@ -50,3 +52,6 @@ secrets:
|
||||||
access_token:
|
access_token:
|
||||||
external: true
|
external: true
|
||||||
name: ${STACK_NAME}_access_token_${SECRET_MASTODON_ACCESS_TOKEN}
|
name: ${STACK_NAME}_access_token_${SECRET_MASTODON_ACCESS_TOKEN}
|
||||||
|
app_password:
|
||||||
|
external: true
|
||||||
|
name: ${STACK_NAME}_app_password_${SECRET_NEXTCLOUD_APP_PASSWORD}
|
||||||
|
|
|
@ -24,6 +24,7 @@ file_env() {
|
||||||
}
|
}
|
||||||
|
|
||||||
file_env "MASTODON_ACCESS_TOKEN"
|
file_env "MASTODON_ACCESS_TOKEN"
|
||||||
|
file_env "NEXTCLOUD_APP_PASSWORD"
|
||||||
|
|
||||||
echo "Passing it back to the upstream ENTRYPOINT/CMD..."
|
echo "Passing it back to the upstream ENTRYPOINT/CMD..."
|
||||||
exec "$@"
|
exec "$@"
|
||||||
|
|
|
@ -258,6 +258,25 @@ category = "dev"
|
||||||
optional = false
|
optional = false
|
||||||
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
|
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pyocclient"
|
||||||
|
version = "0.4"
|
||||||
|
description = ""
|
||||||
|
category = "main"
|
||||||
|
optional = false
|
||||||
|
python-versions = "*"
|
||||||
|
develop = false
|
||||||
|
|
||||||
|
[package.dependencies]
|
||||||
|
requests = ">=2.0.1"
|
||||||
|
six = "*"
|
||||||
|
|
||||||
|
[package.source]
|
||||||
|
type = "git"
|
||||||
|
url = "https://github.com/decentral1se/pyocclient.git"
|
||||||
|
reference = "patched-madcap-branch"
|
||||||
|
resolved_reference = "be63a32f520b887948f20ae57ca887d85555f720"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "python-dateutil"
|
name = "python-dateutil"
|
||||||
version = "2.8.1"
|
version = "2.8.1"
|
||||||
|
@ -433,7 +452,7 @@ python-versions = ">=3.6.1"
|
||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "1.1"
|
lock-version = "1.1"
|
||||||
python-versions = "^3.9"
|
python-versions = "^3.9"
|
||||||
content-hash = "85c658e333aaf6d368f65e4fdaec48b721db82160dc31f5bdadfad7d3ca36da0"
|
content-hash = "2f8f656acf6e4dca956d207427e94a3d7ab2054ec1109e52ee895e5fe833215d"
|
||||||
|
|
||||||
[metadata.files]
|
[metadata.files]
|
||||||
appdirs = [
|
appdirs = [
|
||||||
|
@ -582,6 +601,7 @@ pyflakes = [
|
||||||
{file = "pyflakes-2.3.1-py2.py3-none-any.whl", hash = "sha256:7893783d01b8a89811dd72d7dfd4d84ff098e5eed95cfa8905b22bbffe52efc3"},
|
{file = "pyflakes-2.3.1-py2.py3-none-any.whl", hash = "sha256:7893783d01b8a89811dd72d7dfd4d84ff098e5eed95cfa8905b22bbffe52efc3"},
|
||||||
{file = "pyflakes-2.3.1.tar.gz", hash = "sha256:f5bc8ecabc05bb9d291eb5203d6810b49040f6ff446a756326104746cc00c1db"},
|
{file = "pyflakes-2.3.1.tar.gz", hash = "sha256:f5bc8ecabc05bb9d291eb5203d6810b49040f6ff446a756326104746cc00c1db"},
|
||||||
]
|
]
|
||||||
|
pyocclient = []
|
||||||
python-dateutil = [
|
python-dateutil = [
|
||||||
{file = "python-dateutil-2.8.1.tar.gz", hash = "sha256:73ebfe9dbf22e832286dafa60473e4cd239f8592f699aa5adaf10050e6e1823c"},
|
{file = "python-dateutil-2.8.1.tar.gz", hash = "sha256:73ebfe9dbf22e832286dafa60473e4cd239f8592f699aa5adaf10050e6e1823c"},
|
||||||
{file = "python_dateutil-2.8.1-py2.py3-none-any.whl", hash = "sha256:75bb3f31ea686f1197762692a9ee6a7550b59fc6ca3a1f4b5d7e32fb98e2da2a"},
|
{file = "python_dateutil-2.8.1-py2.py3-none-any.whl", hash = "sha256:75bb3f31ea686f1197762692a9ee6a7550b59fc6ca3a1f4b5d7e32fb98e2da2a"},
|
||||||
|
|
22
pubspace.py
22
pubspace.py
|
@ -1,12 +1,17 @@
|
||||||
import logging
|
import logging
|
||||||
from os import environ
|
from os import environ
|
||||||
|
|
||||||
|
import owncloud
|
||||||
from fastapi import FastAPI, Request
|
from fastapi import FastAPI, Request
|
||||||
from mastodon import Mastodon, StreamListener
|
from mastodon import Mastodon, StreamListener
|
||||||
|
|
||||||
MASTODON_ACCESS_TOKEN = environ.get("MASTODON_ACCESS_TOKEN")
|
MASTODON_ACCESS_TOKEN = environ.get("MASTODON_ACCESS_TOKEN")
|
||||||
MASTODON_API_BASE_URL = environ.get("MASTODON_API_BASE_URL")
|
MASTODON_API_BASE_URL = environ.get("MASTODON_API_BASE_URL")
|
||||||
|
|
||||||
|
NEXTCLOUD_API_BASE_URL = environ.get("NEXTCLOUD_API_BASE_URL")
|
||||||
|
NEXTCLOUD_USER = environ.get("NEXTCLOUD_USER")
|
||||||
|
NEXTCLOUD_APP_PASSWORD = environ.get("NEXTCLOUD_APP_PASSWORD")
|
||||||
|
|
||||||
APP_LOG_LEVEL = environ.get("APP_LOG_LEVEL")
|
APP_LOG_LEVEL = environ.get("APP_LOG_LEVEL")
|
||||||
if APP_LOG_LEVEL == "info":
|
if APP_LOG_LEVEL == "info":
|
||||||
APP_LOG_LEVEL = logging.INFO
|
APP_LOG_LEVEL = logging.INFO
|
||||||
|
@ -19,6 +24,7 @@ mastodon = Mastodon(
|
||||||
access_token=MASTODON_ACCESS_TOKEN,
|
access_token=MASTODON_ACCESS_TOKEN,
|
||||||
api_base_url=f"https://{MASTODON_API_BASE_URL}",
|
api_base_url=f"https://{MASTODON_API_BASE_URL}",
|
||||||
)
|
)
|
||||||
|
nextcloud = owncloud.Client(f"https://{NEXTCLOUD_API_BASE_URL}")
|
||||||
|
|
||||||
log = logging.getLogger("uvicorn")
|
log = logging.getLogger("uvicorn")
|
||||||
log.setLevel(APP_LOG_LEVEL)
|
log.setLevel(APP_LOG_LEVEL)
|
||||||
|
@ -33,12 +39,26 @@ class PubspaceListener(StreamListener):
|
||||||
|
|
||||||
|
|
||||||
mastodon.stream_hashtag("pubspace", PubspaceListener(), run_async=True)
|
mastodon.stream_hashtag("pubspace", PubspaceListener(), run_async=True)
|
||||||
|
nextcloud.login(NEXTCLOUD_USER, NEXTCLOUD_APP_PASSWORD)
|
||||||
|
|
||||||
|
|
||||||
|
def create_share(fpath):
|
||||||
|
if not nextcloud.is_shared(fpath):
|
||||||
|
info = nextcloud.share_file_with_link(fpath)
|
||||||
|
return info.get_link()
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
async def home(request: Request):
|
async def home(request: Request):
|
||||||
try:
|
try:
|
||||||
app.state.log.info(await request.json())
|
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:
|
except Exception:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ python = "^3.9"
|
||||||
fastapi = "^0.65.2"
|
fastapi = "^0.65.2"
|
||||||
uvicorn = {extras = ["standard"], version = "^0.14.0"}
|
uvicorn = {extras = ["standard"], version = "^0.14.0"}
|
||||||
"Mastodon.py" = "^1.5.1"
|
"Mastodon.py" = "^1.5.1"
|
||||||
|
pyocclient = { git = "https://github.com/decentral1se/pyocclient.git", branch = "patched-madcap-branch" }
|
||||||
|
|
||||||
[tool.poetry.dev-dependencies]
|
[tool.poetry.dev-dependencies]
|
||||||
black = "^21.6b0"
|
black = "^21.6b0"
|
||||||
|
|
Reference in New Issue