You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-06 09:19:22 +02:00
Improved logic to set resource file size
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const BaseItem = require('lib/models/BaseItem');
|
||||
const Resource = require('lib/models/Resource');
|
||||
const ResourceService = require('lib/services/ResourceService');
|
||||
const { Logger } = require('lib/logger.js');
|
||||
|
||||
class DecryptionWorker {
|
||||
@@ -132,6 +133,10 @@ class DecryptionWorker {
|
||||
throw error;
|
||||
}
|
||||
|
||||
// 2019-05-12: Temporary to set the file size of the resources
|
||||
// that weren't set in migration/20.js due to being on the sync target
|
||||
await ResourceService.autoSetFileSizes();
|
||||
|
||||
this.logger().info('DecryptionWorker: completed decryption.');
|
||||
|
||||
this.dispatchReport({ state: 'idle' });
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const Resource = require('lib/models/Resource');
|
||||
const BaseService = require('lib/services/BaseService');
|
||||
const ResourceService = require('lib/services/ResourceService');
|
||||
const BaseSyncTarget = require('lib/BaseSyncTarget');
|
||||
const { Logger } = require('lib/logger.js');
|
||||
const EventEmitter = require('events');
|
||||
@@ -103,14 +104,17 @@ class ResourceFetcher extends BaseService {
|
||||
// 2019-05-12: This is only necessary to set the file size of the resources that come via
|
||||
// sync. The other ones have been done using migrations/20.js. This code can be removed
|
||||
// after a few months.
|
||||
if (resource.size < 0 && localResourceContentPath) {
|
||||
const itDoes = await shim.fsDriver().waitTillExists(localResourceContentPath);
|
||||
const fileStat = await shim.fsDriver().stat(localResourceContentPath);
|
||||
await Resource.setFileSizeOnly(resource.id, fileStat.size);
|
||||
if (resource.size < 0 && localResourceContentPath && !resource.encryption_blob_encrypted) {
|
||||
await ResourceService.autoSetFileSizes();
|
||||
}
|
||||
|
||||
delete this.fetchingItems_[resource.id];
|
||||
this.scheduleQueueProcess();
|
||||
|
||||
// Note: This downloadComplete event is not really right or useful because the resource
|
||||
// might still be encrypted and the caller usually can't do much with this. In particular
|
||||
// the note being displayed will refresh the resource images but since they are still
|
||||
// encrypted it's not useful. Probably, the views should listen to DecryptionWorker events instead.
|
||||
if (emitDownloadComplete) this.eventEmitter_.emit('downloadComplete', { id: resource.id });
|
||||
this.updateReport();
|
||||
}
|
||||
|
||||
@@ -111,6 +111,20 @@ class ResourceService extends BaseService {
|
||||
}
|
||||
}
|
||||
|
||||
static async autoSetFileSize(resourceId, filePath) {
|
||||
const itDoes = await shim.fsDriver().waitTillExists(filePath);
|
||||
const fileStat = await shim.fsDriver().stat(filePath);
|
||||
await Resource.setFileSizeOnly(resourceId, fileStat.size);
|
||||
}
|
||||
|
||||
static async autoSetFileSizes() {
|
||||
const resources = await Resource.needFileSizeSet();
|
||||
|
||||
for (const r of resources) {
|
||||
await this.autoSetFileSize(r.id, Resource.fullPath(r));
|
||||
}
|
||||
}
|
||||
|
||||
async maintenance() {
|
||||
await this.indexNoteResources();
|
||||
await this.deleteOrphanResources();
|
||||
|
||||
Reference in New Issue
Block a user