Created
March 18, 2013 13:35
-
-
Save simong/5187165 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Startup | |
| All the storage backends register themselves. | |
| ContentAPI.Backends.register('local', require('backends/local')) | |
| ContentAPI.Backends.register('amazons3', require('backends/amazons3')) | |
| ... | |
| # An upload request | |
| 1. User uploads to /api/content/create | |
| 2. Gets routed to ContentAPI.createFile | |
| 3. Calls down to: | |
| var backend = BackendRegistery.getBackend(ctx, file); | |
| 4. The registry iterates over all the known backends | |
| var scores = [] | |
| for backend in backends: | |
| var score = backend.getSuitability(ctx, file) | |
| // Negative score means this backend can't or won't handle the file | |
| if (score >= 0): | |
| scores.push(score) | |
| scores.sort() | |
| return scores[0] | |
| 5. ContentAPI does backend.store(... | |
| Examples of the getSuitability impl for a storage backend. | |
| // The local one | |
| def getSuitability(ctx, file): | |
| if not enabled: | |
| return -1 | |
| else | |
| return 0 | |
| // The Kaltura one | |
| var mimetypes = ['video/x-msvideo', 'video/x-dv'] | |
| def getSuitability(ctx, file): | |
| if not enabled: | |
| return -1 | |
| else: | |
| if file.type in mimetypes: | |
| // Kaltura is more important than the local one. | |
| return 10 | |
| else: | |
| return 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment