├── .gitignore ├── package.json ├── scripts └── index.js ├── .github └── workflows │ └── commit.yml └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "shortcuts-cfimages-action", 3 | "version": "1.0.0", 4 | "type": "module", 5 | "description": "", 6 | "main": "scripts/index.js", 7 | "keywords": [], 8 | "author": "Mu-An Chiou", 9 | "license": "MIT" 10 | } 11 | -------------------------------------------------------------------------------- /scripts/index.js: -------------------------------------------------------------------------------- 1 | import fs from 'fs' 2 | import path from 'path' 3 | 4 | const filePath = process.argv[2] 5 | const jsonString = process.argv[3] 6 | const fileExists = fs.existsSync(filePath) 7 | 8 | const photos = fileExists ? JSON.parse(fs.readFileSync(filePath).toString()) : [] 9 | const json = JSON.parse(jsonString) 10 | photos.push(json) 11 | 12 | const dirName = path.dirname(filePath) 13 | if (!fileExists && dirName !== '.') { 14 | fs.mkdirSync(dirName, {recursive: true}) 15 | } 16 | 17 | fs.writeFileSync(filePath, JSON.stringify(photos, null, 2)) 18 | -------------------------------------------------------------------------------- /.github/workflows/commit.yml: -------------------------------------------------------------------------------- 1 | on: 2 | workflow_dispatch: 3 | inputs: 4 | filepath: 5 | description: "JSON file path for the data" 6 | type: string 7 | required: true 8 | filedata: 9 | description: "Stringify JSON data of the image" 10 | type: string 11 | required: true 12 | name: 13 | description: "git config user.name" 14 | type: string 15 | required: true 16 | email: 17 | description: "git config user.email" 18 | type: string 19 | required: true 20 | 21 | jobs: 22 | process: 23 | runs-on: ubuntu-latest 24 | 25 | steps: 26 | - uses: actions/checkout@v3 27 | - uses: actions/setup-node@v3 28 | with: 29 | node-version: 17.7 30 | 31 | - name: Run script 32 | run: node scripts/index.js '${{ inputs.filepath }}' '${{ inputs.filedata }}' 33 | 34 | - name: Push changes 35 | run: | 36 | git config user.email '${{ inputs.email }}' 37 | git config user.name '${{ inputs.name }}' 38 | git add . 39 | git commit -m "Add photo from Apple shortcuts" || echo "Nothing to commit" 40 | git fetch origin main 41 | git push origin HEAD:main 42 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # shortcuts-cfimages-action 2 | 3 | This repository guides you through setting up a workflow to upload photos from your Apple device to Cloudflare Images, then trigger a GitHub Action which commits the upload response into your repository, for you to do whatever with; for example, you can use it to [build a RSS feed of photos](https://muan.co/photos.xml). 4 | 5 | ## Setup 6 | 7 | Step 1: Sign up for [Cloudflare Images](https://www.cloudflare.com/products/cloudflare-images/). 8 | 9 | Step 2: Fork this repository. Alternatively, set up a GitHub Action like [`commit.yml`](.github/workflows/commit.yml) to receive the uploaded image metadata. The  Shortcut in the next step assumes you are using `commit.yml`, but it shouldn't be hard to customize. 10 | 11 | Step 3: Install this [ Shortcut](https://www.icloud.com/shortcuts/accdd822b5c0461eaaf24c6219ed9699) and respond to setup questions with your Cloudflare credentials and the details of your GitHub Action. 12 | 13 | ### Cloudflare Images 14 | 15 | Cloudflare Images costs $60/year, but it takes care of serving and resizing your images in the most optimal way. Alternatively, check out [muan/stories-feed-action](https://github.com/muan/stories-feed-action) which simply commits photos into your repository. 16 | 17 | #### **Cloudflare API Token** 18 | 19 | https://dash.cloudflare.com/profile/api-tokens → Create Token 20 | 21 | #### **Cloudflare Images Account ID** 22 | 23 | https://dash.cloudflare.com/ → Images → Developer Resources → Account ID 24 | 25 | ### `commit.yml` or a custom GitHub Action 26 | 27 | This action takes the successful response from a Cloudflare Images upload, and appends it to a JSON file you specifiy. 28 | 29 | ###  Shortcut 30 | 31 | The shortcut does the following: 32 | 33 | - Prompt to select photo 34 | - Prompt for caption and alt text 35 | - Upload photo to Cloudflare Images with the caption/alt as its metadata 36 | - Trigger a `workflow_dispatch` event for a GitHub action with the response from the success upload 37 | 38 | The `workflow_dispatch` action depends on the [GitHub iOS app](https://apps.apple.com/app/github/id1477376905). 39 | --------------------------------------------------------------------------------