Skip to content

Commit 2b9802b

Browse files
authored
Merge pull request SNathJr#54 from badrihippo/master
Add support for WebDAV storage adapter
2 parents 842970d + 0b3204c commit 2b9802b

File tree

6 files changed

+157
-3
lines changed

6 files changed

+157
-3
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,34 @@ heroku addons:create bucketeer --app YOURAPPNAME
8686
heroku config:set S3_BUCKET_REGION=us-east-1 --app YOURAPPNAME
8787
```
8888

89+
#### Configuring WebDAV file uploads
90+
91+
As an alternative to S3 and Cloudinary, you can also use your own WebDAV server, via the [ghost-webdav-adapter](https://github.com/bartt/ghost-webdav-storage-adapter) plugin. To use these, simply specify the following details as environment variables on the Heroku deployment page (or add these environment variables to your app after deployment via the Heroku dashboard):
92+
93+
- `WEBDAV_SERVER_URL`: **Required if using WebDAV uploads**. The URL to access your WebDAV server. Note that this requires the `https` format (not `dav://` or `davs://`). Example: `https://mysite.com:2078`.
94+
95+
- `WEBDAV_USERNAME` and `WEBDAV_PASSWORD`: Optional even if using WebDAV uploads. These are the username and password used to log in to your WebDAV account. Unless you're using an open and unsecured server, you'll probably need to set these options too.
96+
97+
- `WEBDAV_PATH_PREFIX`: Optional even if using WebDAV uploads. Subfolder on the WebDAV server where you want to store the files. Defaults to the main directory or `/`. Example: `/ghost-uploads`.
98+
99+
- `WEBDAV_STORAGE_PATH_PREFIX`: Optional even if using WebDAV uploads. This is the location where the public will be able to access the uploaded file. Defaults to `content/`, which makes Ghost server the files for you, but can also be an external domain such as `https://media.mysite.com/ghost-files`.
100+
101+
The difference between `WEBDAV_PATH_PREFIX` and `WEBDAV_STORAGE_PATH_PREFIX` is this: you *upload* the files to `WEBDAV_PATH_PREFIX` via WebDAV, but you *download* them from `WEBDAV_STORAGE_PATH_PREFIX` using ordinary HTTP.
102+
103+
For more detailed information, you can refer to [the ghost-webdav-adapter repo](https://github.com/bartt/ghost-webdav-storage-adapter)
104+
105+
##### Known Issue
106+
107+
There is a bug (that only occurs sometimes): when uploading a file to a subdirectory, it creates one level of the directory and then fails, so you have to retry to get to the next level. For example: if it wants to save the file 2020/06/12/example.jpg but only the 2020 folder exists, then it will take three tries (refresh the page and upload again) to get it working:
108+
109+
- create 2020/06 and fail
110+
- create 2020/06/12 and fail
111+
- upload the file to 2020/06/12/example.jpg
112+
113+
This seems to be a bug in the storage adapter plugin itself (yet to be reported).
114+
115+
**Note:** Remember to **refresh** the page on each retry. Retrying without refreshing the page does not seem to work. If you don't succeed after 3-4 tries, there might be something else wrong with your configuration.
116+
89117
#### Setting up SMTP service
90118

91119
When you spin up your heroku dyno for the first time, mailgun is by default setup with a sandbox account. It means, sending emails to only authorized reciepients is supported. If you want to send emails / invite your collaborators you need to set their email in authorized recipient section on mailgun dashboard. See https://help.mailgun.com/hc/en-us/articles/217531258-Authorized-Recipients for more.

app.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,26 @@
3636
"S3_ASSET_HOST_URL": {
3737
"description": "Optional custom CDN asset host url, if using S3 file storage.",
3838
"required": false
39+
},
40+
"WEBDAV_SERVER_URL": {
41+
"description": "URL of your WebDAV server, if using WebDAV file storage",
42+
"required": false
43+
},
44+
"WEBDAV_USERNAME": {
45+
"description": "Username for your WebDAV server, if using WebDAV file storage",
46+
"required": false
47+
},
48+
"WEBDAV_PASSWORD": {
49+
"description": "Password for your WebDAV server, if using WebDAV file storage",
50+
"required": false
51+
},
52+
"WEBDAV_PATH_PREFIX": {
53+
"description": "Optional path prefix for your WebDAV server, if using WebDAV file storage",
54+
"required": false
55+
},
56+
"WEBDAV_STORAGE_PATH_PREFIX": {
57+
"description": "Optional storage path prefix for your WebDAV server, if using WebDAV file storage",
58+
"required": false
3959
}
4060
}
4161
}

bin/copy-webdav-plugin.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mkdir -p content/adapters/storage/webdav
2+
cp -Rf node_modules/ghost-webdav-storage-adapter/dist/* content/adapters/storage/webdav

bin/create-config

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ function createConfig() {
2323
assetHost: process.env.S3_ASSET_HOST_URL
2424
}
2525
}
26+
} else if (!!process.env.WEBDAV_SERVER_URL){
27+
fileStorage = true
28+
storage = {
29+
'active': 'webdav',
30+
// no need to set configs; they're set directly from
31+
// the environment variables.
32+
}
2633
} else if (!!process.env.BUCKETEER_AWS_ACCESS_KEY_ID) {
2734
fileStorage = true
2835
storage = {

package-lock.json

Lines changed: 98 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"ghost": "^3.2.0",
1717
"ghost-storage-adapter-s3": "^2.8.0",
1818
"ghost-storage-cloudinary": "^2.0.2",
19+
"ghost-webdav-storage-adapter": "^0.3.5",
1920
"london": "github:tryghost/london#1.0.0",
2021
"massively": "github:tryghost/massively#1.0.2",
2122
"mysql": "^2.17.1",
@@ -30,6 +31,6 @@
3031
},
3132
"scripts": {
3233
"start": "node server.js",
33-
"postinstall": "bash bin/copy-themes.sh"
34+
"postinstall": "bash bin/copy-themes.sh && bash bin/copy-webdav-plugin.sh"
3435
}
3536
}

0 commit comments

Comments
 (0)