mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-18 09:35:20 +02:00
Cli: Make Sharp package optional
This commit is contained in:
parent
d1ea90cd5c
commit
388d124d91
@ -408,6 +408,8 @@ class Application extends BaseApplication {
|
|||||||
|
|
||||||
this.initRedux();
|
this.initRedux();
|
||||||
|
|
||||||
|
if (!shim.sharpEnabled()) this.logger().warn('Sharp is disabled - certain image-related features will not be available');
|
||||||
|
|
||||||
// If we have some arguments left at this point, it's a command
|
// If we have some arguments left at this point, it's a command
|
||||||
// so execute it.
|
// so execute it.
|
||||||
if (argv.length) {
|
if (argv.length) {
|
||||||
|
@ -22,7 +22,6 @@ const Setting = require('@joplin/lib/models/Setting').default;
|
|||||||
const Revision = require('@joplin/lib/models/Revision').default;
|
const Revision = require('@joplin/lib/models/Revision').default;
|
||||||
const Logger = require('@joplin/utils/Logger').default;
|
const Logger = require('@joplin/utils/Logger').default;
|
||||||
const FsDriverNode = require('@joplin/lib/fs-driver-node').default;
|
const FsDriverNode = require('@joplin/lib/fs-driver-node').default;
|
||||||
const sharp = require('sharp');
|
|
||||||
const { shimInit } = require('@joplin/lib/shim-init-node.js');
|
const { shimInit } = require('@joplin/lib/shim-init-node.js');
|
||||||
const shim = require('@joplin/lib/shim').default;
|
const shim = require('@joplin/lib/shim').default;
|
||||||
const { _ } = require('@joplin/lib/locale');
|
const { _ } = require('@joplin/lib/locale');
|
||||||
@ -32,6 +31,14 @@ const envFromArgs = require('@joplin/lib/envFromArgs');
|
|||||||
const nodeSqlite = require('sqlite3');
|
const nodeSqlite = require('sqlite3');
|
||||||
const initLib = require('@joplin/lib/initLib').default;
|
const initLib = require('@joplin/lib/initLib').default;
|
||||||
|
|
||||||
|
let sharp = null;
|
||||||
|
try {
|
||||||
|
sharp = require('sharp');
|
||||||
|
} catch (error) {
|
||||||
|
// Don't print an error or it will pollute stdout every time the app is started. A warning will
|
||||||
|
// be printed in app.ts
|
||||||
|
}
|
||||||
|
|
||||||
const env = envFromArgs(process.argv);
|
const env = envFromArgs(process.argv);
|
||||||
|
|
||||||
const fsDriver = new FsDriverNode();
|
const fsDriver = new FsDriverNode();
|
||||||
|
@ -18,6 +18,7 @@ import crypto from './services/e2ee/crypto';
|
|||||||
import FileApiDriverLocal from './file-api-driver-local';
|
import FileApiDriverLocal from './file-api-driver-local';
|
||||||
import * as mimeUtils from './mime-utils';
|
import * as mimeUtils from './mime-utils';
|
||||||
import BaseItem from './models/BaseItem';
|
import BaseItem from './models/BaseItem';
|
||||||
|
import { Size } from '@joplin/utils/types';
|
||||||
const { _ } = require('./locale');
|
const { _ } = require('./locale');
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
const https = require('https');
|
const https = require('https');
|
||||||
@ -146,6 +147,10 @@ function shimInit(options: ShimInitOptions = null) {
|
|||||||
return shim.fsDriver_;
|
return shim.fsDriver_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
shim.sharpEnabled = () => {
|
||||||
|
return !!sharp;
|
||||||
|
};
|
||||||
|
|
||||||
shim.dgram = () => {
|
shim.dgram = () => {
|
||||||
return dgram;
|
return dgram;
|
||||||
};
|
};
|
||||||
@ -270,10 +275,17 @@ function shimInit(options: ShimInitOptions = null) {
|
|||||||
return await saveOriginalImage();
|
return await saveOriginalImage();
|
||||||
} else {
|
} else {
|
||||||
// For the CLI tool
|
// For the CLI tool
|
||||||
const image = sharp(filePath);
|
|
||||||
const md = await image.metadata();
|
|
||||||
|
|
||||||
if (md.width <= maxDim && md.height <= maxDim) {
|
let md: Size = null;
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
let image: any = null;
|
||||||
|
|
||||||
|
if (sharp) {
|
||||||
|
image = sharp(filePath);
|
||||||
|
md = await image.metadata();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!md || (md.width <= maxDim && md.height <= maxDim)) {
|
||||||
await shim.fsDriver().copy(filePath, targetPath);
|
await shim.fsDriver().copy(filePath, targetPath);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -299,6 +299,10 @@ const shim = {
|
|||||||
throw new Error('Not implemented: fsDriver');
|
throw new Error('Not implemented: fsDriver');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
sharpEnabled: (): boolean => {
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
|
||||||
FileApiDriverLocal: null as typeof FileApiDriverLocal,
|
FileApiDriverLocal: null as typeof FileApiDriverLocal,
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
||||||
|
Loading…
Reference in New Issue
Block a user