You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-06-15 23:00:36 +02:00
Clipper: Download images and convert them to resources
This commit is contained in:
@ -96,7 +96,7 @@ function shimInit() {
|
||||
}
|
||||
}
|
||||
|
||||
shim.attachFileToNote = async function(note, filePath, position = null) {
|
||||
shim.createResourceFromPath = async function(filePath) {
|
||||
const Resource = require('lib/models/Resource.js');
|
||||
const { uuid } = require('lib/uuid.js');
|
||||
const { basename, fileExtension, safeFileExtension } = require('lib/path-utils.js');
|
||||
@ -126,6 +126,41 @@ function shimInit() {
|
||||
|
||||
await Resource.save(resource, { isNew: true });
|
||||
|
||||
return resource;
|
||||
}
|
||||
|
||||
shim.attachFileToNote = async function(note, filePath, position = null) {
|
||||
// const Resource = require('lib/models/Resource.js');
|
||||
// const { uuid } = require('lib/uuid.js');
|
||||
// const { basename, fileExtension, safeFileExtension } = require('lib/path-utils.js');
|
||||
// const mime = require('mime/lite');
|
||||
// const Note = require('lib/models/Note.js');
|
||||
|
||||
// if (!(await fs.pathExists(filePath))) throw new Error(_('Cannot access %s', filePath));
|
||||
|
||||
// let resource = Resource.new();
|
||||
// resource.id = uuid.create();
|
||||
// resource.mime = mime.getType(filePath);
|
||||
// resource.title = basename(filePath);
|
||||
// resource.file_extension = safeFileExtension(fileExtension(filePath));
|
||||
|
||||
// if (!resource.mime) resource.mime = 'application/octet-stream';
|
||||
|
||||
// let targetPath = Resource.fullPath(resource);
|
||||
|
||||
// if (resource.mime == 'image/jpeg' || resource.mime == 'image/jpg' || resource.mime == 'image/png') {
|
||||
// const result = await resizeImage_(filePath, targetPath, resource.mime);
|
||||
// } else {
|
||||
// const stat = await shim.fsDriver().stat(filePath);
|
||||
// if (stat.size >= 10000000) throw new Error('Resources larger than 10 MB are not currently supported as they may crash the mobile applications. The issue is being investigated and will be fixed at a later time.');
|
||||
|
||||
// await fs.copy(filePath, targetPath, { overwrite: true });
|
||||
// }
|
||||
|
||||
// await Resource.save(resource, { isNew: true });
|
||||
|
||||
const resource = shim.createResourceFromPath(filePath);
|
||||
|
||||
const newBody = [];
|
||||
|
||||
if (position === null) {
|
||||
|
Reference in New Issue
Block a user