[draft] DGPF-extensible rendering of files based on public URL#244
[draft] DGPF-extensible rendering of files based on public URL#244abought wants to merge 13 commits into
Conversation
And add more exports to module to support custom renderers
80e30eb to
23cd9d9
Compare
| **page_options, | ||
| "render_options": render_options, | ||
| } | ||
| ) |
There was a problem hiding this comment.
How is this view going to be used in practice? Most "previewed" images and such will be done across multiple pages. This could potentially be done in an iFrame, but I'm unsure.
A better way might be creating an API method instead, that returns the required info as needed. An alternative to this was already implemented here, which allows asynchronously fetching a token using javascript for later use by the page (loading images and such)
There was a problem hiding this comment.
Eventually planning to refactor to iframe srcdoc and simplifying to api token for what is fetched; refactor planned next week.
There was a problem hiding this comment.
Would you be available this week to workshop some ideas for the django <-> JS interface on a file renderer? Some changes pushed based on tweaks. Best days this week are Tues / Wed.
The current interface between backend and frontend is a bit baroque- it exposes a lot of power, and it could be worse... but it also imposes some mental overhead on the developer. Honestly, it's easier to discuss synchronously (with live demo) to start.
At its heart, the render logic consists of a JS function, doRender, that is passed certain variables from a template. The surrounding template partial fills in the boilerplate, but a page with multiple files could just as easily call that function however it wants.
When it's time to use that function, we need to take advantage of any view function, and ideally without having to rewrite the view function. To inject the functionality, this uses three pieces:
- A template tag that turns a given search result into the dict we need (including translating the collection ID into a URL)
- A user-extensible template which allows adding any custom render logic (like a PDB viewer)
- A backend token endpoint that checks against a whitelist of collection IDs. (I have some questions about DGPF functionality for how to improve this)
I had originally used a URL to abstract this away, which was great for injecting a bundle of functionality into a template; this approach was replaced with the django partial for reasons we could discuss live.
There was a problem hiding this comment.
Setting aside some time to talk about this would be good. This is generally a pretty hard problem to "automatically" with with little user/developer interaction. My ideal list of contradictory items would be:
- User can configure items (like images, but not exclusively) to be rendered from search data
- This functionality is not tied to a single view
- This feature is flexible enough to be used on non-search-related views (User hardcodes items to be rendered)
We do need backend processing for some items like:
- Fetching https access tokens
- Determining collection ids from https links (This is actually difficult and maybe unsupported) or creating https links from collection ids (Requires transfer tokens, which we probably don't want to expose).
We could do the backend processing in templatetags or separate API views. templatetags are less ideal if it incudes network calls to Globus Transfer. I think it would be most ideal if we could specify Globus Collection items to be rendered using Django templates.
I'll ping you on Slack to talk more!
- get-token as separate endpoint - whitelist of collections that can be used with preview feature - cached authentication helper - Move logic into renderers.js and remove main.js
Although it made it much simpler to use this feature, allowing arbitrary URLs exposed the site to url-specified external content. The more baroque template helper system locks it so that users can only render assets described in the search index.
Allows user to select a facet by clicking either the word or the associated label. (a nice bit of convenience)
🦑 Not a candidate for merge. Here to communicate work in progress, currently targeting my own needs. Very much a work in progress, so there are some big quirks!
Purpose
Demonstrate a possible mechanism for rendering files within DGPF based on a public URL, with a pathway towards showing private files later.
Current state
NOT a candidate for merge, but exposing to show one option if there is broader interest. UUID of test collection / search index available on request.
Feature set
To see if the rendering is generic enough to be extensible, I've written crude renderers for image, text, source code highlighting, interactive data tables, PDF, and will write a custom page with interactive widgets around PDB files next.
Arch plan
This PR encompasses:
/<index>/render?url=&collection_uuid=&path=that can render either a public URL, or (eventually) auto-fetch user-approved bearer tokens for private file access (internally translatingcollection_uuid+pathinto an https url for that collection)The path to a more generic featureset would be:
Open questions
The main open question is around token leakage. To avoid proxying file requests through the web app, we need to pass a token to the frontend.
The
<collection>/httpstoken may have substantially more power than just viewing files. And because all scopes on a resource server are attached to a single token, if a custom DGPF carries extra scopes, then a leaked token could be exfiltrated and used to do a lot of other stuff on behalf of a user. That would be.... bad.Open for discussion/ brainstorming here!
Using the view
Since my test case is a private repo, examples are produced below. These are very crude and will evolve as PR grows.
Extensibility mechanism
Below is a real world example of an index-specific override, showing that the extensibility mechanism allows defining project-specific custom renderers.
TODO
The following items are based on my own needs, and represent a potential way forward if this ever seemed useful for others.
Features
Technology
[ ] Review current state around native ESM in browser. If the team is concerned about compat, parcel/vite/etc may be useful- but this comes with tradeoffs.
collectionswhitelist. Missing use case: "this asset is public and no token needed, but I still want to translate collection ID into URL".objecttag members using src url instead of blob. For native video elements, this might enable streaming use case