mitodl / ocw-studio

Open Source Courseware authoring tool
BSD 3-Clause "New" or "Revised" License
9 stars 3 forks source link

resources published locally include storage bucket in URL #2117

Closed gumaerc closed 7 months ago

gumaerc commented 7 months ago

Expected Behavior

The file property in the front matter of markdown files published by ocw-studio locally are relative paths pointing to the file from the root of any given host

Current Behavior

The file property is prefixed with the value of AWS_STORAGE_BUCKET_NAME, i.e. /ol-ocw-studio-app/courses/ocw-ci-test-course/example_pdf.pdf

Steps to Reproduce

  1. Import or create a course in ocw-studio using the local Docker setup
  2. Publish said course
  3. Browse to the Github repo for the course and find a resource

Possible Solution

When using the setting OCW_STUDIO_USE_S3=true, the django-storages backend automatically generates the url property of FileFields using the configured AWS settings. In local development, AWS settings are overridden to use a locally running instance of Minio. An automatically generated URL to a resource in AWS proper looks something like: 'https://ol-ocw-studio-app-qa.s3.amazonaws.com/courses/6-450-principles-of-digital-communications-i-fall-2006/c59828b4e470fd50daf31f0f7251456c_quiz1_04_soln.pdf'. Locally, you will see URLs like 'http://10.1.0.100:9000/ol-ocw-studio-app/courses/ocw-ci-test-course/example_pdf.pdf'. This happens because endpoint_url is overridden to hit Minio, and a different URL strategy is used.

In the full_metadata property of the WebsiteContent model, the file URL is set using full_metadata[file_field["name"]] = urlparse(file_url).path. If you look at the above URLs, you will see why the bucket name is being included locally. Since the bucket name is part of the path and not the domain, it gets included when you call the path property of the parsed URL. The bucket name should be filtered out of the path if it is being included.

gumaerc commented 7 months ago

Closing this issue, as it was found to be an issue with my local configuration as noted in https://github.com/mitodl/ocw-studio/pull/2124