Skip to content

Commit

Permalink
v1.0.3 - allow nc_url with / or index.php in the end
Browse files Browse the repository at this point in the history
  • Loading branch information
bigcat88 committed Oct 11, 2023
1 parent 4fc9075 commit 415a901
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
6 changes: 3 additions & 3 deletions .run/TalkBotAI.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
<env name="AE_VERSION" value="1.0.0" />
<env name="APP_ID" value="talk_bot_ai_example" />
<env name="APP_PERSISTENT_STORAGE" value="$USER_HOME$/persis_storage" />
<env name="APP_PORT" value="9034" />
<env name="APP_PORT" value="10034" />
<env name="APP_SECRET" value="12345" />
<env name="APP_VERSION" value="1.0.0" />
<env name="NEXTCLOUD_URL" value="http://nextcloud.local" />
<env name="AE_VERSION" value="1.0.0" />
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="SDK_NAME" value="Python 3.11 (talk_bot_ai_example)" />
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ help:
.PHONY: build-push
build-push:
docker login ghcr.io
docker buildx build --push --platform linux/arm64/v8,linux/amd64 --tag ghcr.io/cloud-py-api/talk_bot_ai_example:1.0.2 --tag ghcr.io/cloud-py-api/talk_bot_ai_example:latest .
docker buildx build --push --platform linux/arm64/v8,linux/amd64 --tag ghcr.io/cloud-py-api/talk_bot_ai_example:1.0.3 --tag ghcr.io/cloud-py-api/talk_bot_ai_example:latest .

.PHONY: deploy
deploy:
Expand All @@ -45,5 +45,5 @@ run27:
manual_register:
docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:unregister talk_bot_ai_example --silent || true
docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:register talk_bot_ai_example manual_install --json-info \
"{\"appid\":\"talk_bot_ai_example\",\"name\":\"TalkBotAI Example\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"host\":\"host.docker.internal\",\"port\":9034,\"scopes\":{\"required\":[\"TALK\", \"TALK_BOT\"],\"optional\":[]},\"protocol\":\"http\",\"system_app\":0}" \
"{\"appid\":\"talk_bot_ai_example\",\"name\":\"TalkBotAI Example\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"host\":\"host.docker.internal\",\"port\":10034,\"scopes\":{\"required\":[\"TALK\", \"TALK_BOT\"],\"optional\":[]},\"protocol\":\"http\",\"system_app\":0}" \
-e --force-scopes
4 changes: 2 additions & 2 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ It shouldn't be too difficult to use a more advanced model based on this example
Refer to [How to install](https://github.com/cloud-py-api/talk_bot_ai_example/blob/main/HOW_TO_INSTALL.md) to try it.
]]></description>
<version>1.0.2</version>
<version>1.0.3</version>
<licence>MIT</licence>
<author mail="andrey18106x@gmail.com" homepage="https://github.com/andrey18106">Andrey Borysenko</author>
<author mail="bigcat88@icloud.com" homepage="https://github.com/bigcat88">Alexander Piskun</author>
Expand All @@ -32,7 +32,7 @@ Refer to [How to install](https://github.com/cloud-py-api/talk_bot_ai_example/bl
<docker-install>
<registry>ghcr.io</registry>
<image>cloud-py-api/talk_bot_ai_example</image>
<image-tag>1.0.2</image-tag>
<image-tag>1.0.3</image-tag>
</docker-install>
<scopes>
<required>
Expand Down
8 changes: 6 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ def conversation_name(self) -> str:
return self._raw_data["target"]["name"]


def get_nc_url() -> str:
return os.environ["NEXTCLOUD_URL"].removesuffix("/index.php").removesuffix("/")


def sign_request(headers: dict, user="") -> None:
headers["AUTHORIZATION-APP-API"] = b64encode(f"{user}:{os.environ['APP_SECRET']}".encode("UTF=8"))
headers["EX-APP-ID"] = os.environ["APP_ID"]
Expand Down Expand Up @@ -115,7 +119,7 @@ def ocs_call(
sign_request(headers, kwargs.get("user", ""))
return httpx.request(
method,
url=os.environ["NEXTCLOUD_URL"] + path,
url=get_nc_url() + path,
params=params,
content=data_bytes,
headers=headers,
Expand Down Expand Up @@ -155,7 +159,7 @@ def _sign_send_request(method: str, url_suffix: str, data: dict, data_to_sign: s
}
return httpx.request(
method,
url=os.environ["NEXTCLOUD_URL"] + "/ocs/v2.php/apps/spreed/api/v1/bot" + url_suffix,
url=get_nc_url() + "/ocs/v2.php/apps/spreed/api/v1/bot" + url_suffix,
json=data,
headers=headers,
)
Expand Down

0 comments on commit 415a901

Please sign in to comment.