-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
media_folder on widged level #492
Changes from 1 commit
6750c97
db0555d
99fe8ea
44d39f4
b9870a4
414fb76
54bbb7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,14 +8,16 @@ export const setStore = (storeObj) => { | |
store = storeObj; | ||
}; | ||
|
||
export default function AssetProxy(value, fileObj, uploaded = false) { | ||
export default function AssetProxy(value, fileObj, uploaded = false, field_config = null) { | ||
const config = store.getState().config; | ||
const media_folder = field_config && field_config.has('media_folder') ? field_config.get('media_folder') : config.get('media_folder'); | ||
const public_folder = field_config && field_config.has('public_folder') ? field_config.get('public_folder') : '/' + media_folder; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These can shorten up a bit, e.g.: const media_folder = field_config && field_config.get('media_folder') || config.get('media_folder'); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I cannot see if your version has any sideeffects. I prefer longer but self-explaining version |
||
this.value = value; | ||
this.fileObj = fileObj; | ||
this.uploaded = uploaded; | ||
this.sha = null; | ||
this.path = config.get('media_folder') && !uploaded ? resolvePath(value, config.get('media_folder')) : value; | ||
this.public_path = !uploaded ? resolvePath(value, config.get('public_folder')) : value; | ||
this.path = media_folder && !uploaded ? resolvePath(value, media_folder) : value; | ||
this.public_path = !uploaded ? resolvePath(value, public_folder) : value; | ||
} | ||
|
||
AssetProxy.prototype.toString = function () { | ||
|
@@ -39,20 +41,21 @@ AssetProxy.prototype.toBase64 = function () { | |
}); | ||
}; | ||
|
||
export function createAssetProxy(value, fileObj, uploaded = false, privateUpload = false) { | ||
export function createAssetProxy(value, fileObj, uploaded = false, field_config = null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
const state = store.getState(); | ||
const privateUpload = field_config ? field_config.get('private', false) : false; | ||
const integration = selectIntegration(state, null, 'assetStore'); | ||
if (integration && !uploaded) { | ||
const provider = integration && getIntegrationProvider(state.integrations, currentBackend(state.config).getToken, integration); | ||
return provider.upload(fileObj, privateUpload).then( | ||
response => ( | ||
new AssetProxy(response.assetURL.replace(/^(https?):/, ''), null, true) | ||
new AssetProxy(response.assetURL.replace(/^(https?):/, ''), null, true, field_config) | ||
), | ||
error => new AssetProxy(value, fileObj, false) | ||
); | ||
error => new AssetProxy(value, fileObj, false, field_config) | ||
); | ||
} else if (privateUpload) { | ||
throw new Error('The Private Upload option is only avaible for Asset Store Integration'); | ||
} | ||
return Promise.resolve(new AssetProxy(value, fileObj, uploaded)); | ||
|
||
return Promise.resolve(new AssetProxy(value, fileObj, uploaded, field_config)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to keep things minimal in the quick start docs, but this information would be good in
docs/widgets.md
. Extra sections for the image and file widgets can be added, similar to how the relation widget has a separate section.