1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-15 23:00:36 +02:00

All: Added script to build welcome assets and to import them on startup

This commit is contained in:
Laurent Cozic
2019-02-03 18:58:44 +00:00
parent fc416de348
commit 9c00dc4cab
8 changed files with 262 additions and 10 deletions

View File

@ -101,7 +101,7 @@ function shimInit() {
}
}
shim.createResourceFromPath = async function(filePath) {
shim.createResourceFromPath = async function(filePath, defaultProps = null) {
const readChunk = require('read-chunk');
const imageType = require('image-type');
@ -111,8 +111,12 @@ function shimInit() {
if (!(await fs.pathExists(filePath))) throw new Error(_('Cannot access %s', filePath));
defaultProps = defaultProps ? defaultProps : {};
const resourceId = defaultProps.id ? defaultProps.id : uuid.create();
let resource = Resource.new();
resource.id = uuid.create();
resource.id = resourceId;
resource.mime = mime.getType(filePath);
resource.title = basename(filePath);
@ -143,6 +147,10 @@ function shimInit() {
await fs.copy(filePath, targetPath, { overwrite: true });
}
if (defaultProps) {
resource = Object.assign({}, resource, defaultProps);
}
return await Resource.save(resource, { isNew: true });
}