TryGhost / Ghost

Independent technology for modern publishing, memberships, subscriptions and newsletters.
https://ghost.org
MIT License
47.38k stars 10.34k forks source link

Custom storage adapter: req.path returns lowercase URL #9329

Closed sandrotonon closed 6 years ago

sandrotonon commented 6 years ago

Issue Summary

I'm trying to write a custom storage adapter for Google Drive. For this I'm uploading the file in the save() method and resolve a relative URL with the uploaded's file id (which google saves as "aBcDeF" etc.) as qualifier. E.g: content/images/aBcDeF-001.jpg

Now, for reading the image, the base-implementation of serve() looks like this:

serve() { return function customServe(req, res, next) { next(); } (from the docs)

The problem is, that req.path returns the path in lowercase, e.g. "abcdef-001.jpg". So it's not possible to get the file from Google, since the URL is wrongly capitalized.

(See also: https://ghost.slack.com/archives/C04CUS2R3/p1513163969000280)

Expectation: the URL is correctly capitalized, like content/images/aBcDeF-001.jpg.

Is this a ghost/express bug? Or is there a workaround? Thanks in advance!

Technical details:

kirrg001 commented 6 years ago

Hey 👋

serve() { return function customServe(req, res, next) { next(); }

You have to implement the function. There are existing Google Drive adapters, which have implemented the serve fn.

For the future, please do not use our GitHub repo for support. Please read our support guide. You can always use our slack community - https://slack.ghost.org, if you're not able to find the answer in our documentation - https://docs.ghost.org.

sandrotonon commented 6 years ago

Hey,

thanks for your reply.

Yeah, I'm implementing it, but the code is not relevant, since the value of req.path is wrong.

Anyways, this is the code I'm using to get the value of req.path:

serve() {
  var _self = this;

  return function serveStaticContent(req, res, next) {
    console.log('path', req.path);
    // gives lowercase path (e.g. "abcdef.jpg")

    // for furthermore implementation the original path is expected (e.g. "AbCdEf.jpg")

    // [...]
  }
}

Unfortunately the existing google drive adapters are broken, this is why I'm writing a custom one.

I tried to use the slack channel, but didn't get any response. In addition, chances are hight this is a bug.