Skip to content

Commit

Permalink
If appimage is starting send cached capabilities
Browse files Browse the repository at this point in the history
Build script runs AppImage and saves capabilities endpoint
output to file.
When AppImage is not started yet - cached file content will be sent.
Otherwise proxy will redirrect to the acctual endpoint.
  • Loading branch information
eszkadev authored and timar committed Mar 5, 2021
1 parent d22607c commit 82e807e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions build-nextcloud-app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ HASH=`./${app_name}/collabora/Collabora_Online.AppImage --version-hash`
echo "HASH: $HASH"
sed "s/%LOOLWSD_VERSION_HASH%/$HASH/g" ../proxy.php > ${app_name}/proxy.php

# Fetch capabilities from AppImage for cache
PID_FILE="/tmp/loolwsd.pid"
`./${app_name}/collabora/Collabora_Online.AppImage 2>/dev/null` & (sleep 3 && curl "http://localhost:9983/hosting/capabilities" --max-time 10 -o "${app_name}/capabilities.json") || (echo && echo "ERROR: Cannot fetch capabilities!" && echo)
kill -9 `cat $PID_FILE` 2>/dev/null || (echo && echo "Failed to run Collabora Online Appimage" && echo)

# check if we are building for arm64
if [[ "$APPIMAGE_URL" =~ "arm64" ]]; then
echo "Building for arm64"
Expand Down
11 changes: 11 additions & 0 deletions proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,17 @@ function getallheaders()
if ($request == '' && !$statusOnly)
errorExit("Missing, required req= parameter");

if (startsWith($request, '/hosting/capabilities') && !isLoolwsdRunning() && file_exists('capabilities.json')) {
header('Content-type: application/json');
header('Cache-Control: no-store');
$capabilities = file_get_contents('capabilities.json');
if ($capabilities !== false) {
print $capabilities;
http_response_code(200);
exit();
}
}

// If we can't get a socket open in 3 seconds when that is backed by
// a dedicated thread, then we have a server missing in action.
$local = @fsockopen("localhost", 9983, $errno, $errstr, 3);
Expand Down

0 comments on commit 82e807e

Please sign in to comment.