Skip to content

Conversation

ztjhz
Copy link

@ztjhz ztjhz commented Nov 6, 2022

This PR fixes the script for image upload.

Fixes implemented

1. Adapt to strapiv4 api

  • existing.body -> existing.attributes.body
  • _put(`/api/posts/${existing.id}`, existing ) -> _put(`/api/posts/${existing.id}`, { data: existing.attributes })
  • /upload -> /api/upload

2. Handle the absence of attachment_collection.json file

3. Fix image urls that do not start with https://clubs.ntu.edu.sg/csec/ not being uploaded

Remove the following code:

  let wpUploadBase = site.baseUrl + '/wp-content/uploads/';

  if (u.startsWith('http') && !u.startsWith('https')) {
    wpUploadBase = wpUploadBase.replace('https', 'http');
  }
  if (
    u.length <= wpUploadBase.length ||
    u.substring(0, wpUploadBase.length) !== wpUploadBase
  )
    return;

4. Fix placeholder image not being copied correctly

5. Added 2 folders in image uploads: success and fail

  • success: file downloaded successfully
  • fail: file failed to download, placeholder used instead

6. Fix GET posts returning only 25 posts at a time

Instead of fetching the the list of posts at the start, fetch the post one at a time with a filter:

const existing = (
  await _axios.get(`/api/posts?filters[wp_id][$eq]=${wpPost.id}`)
).data.data[0];

[SCSE-105]

@ztjhz ztjhz requested a review from jamiegoh November 6, 2022 05:15
@linear
Copy link

linear bot commented Nov 6, 2022

@ztjhz ztjhz changed the title Fix/image upload/scse 105 Fix image upload Nov 6, 2022
@jamiegoh
Copy link

jamiegoh commented Nov 8, 2022

think some base urls are not https://clubs.ntu.edu.sg/csec so they arent being changed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants