Files
wekan/models
Lauri Ojansivu c2fa9e0b3d Every upload threw in getFileStrategy, so no new file was mime-checked.
From the dev-server log, on a plain attachment upload:

  [onAfterUpload] filename hardening failed: TypeError: Cannot read properties
  of undefined (reading 'gridFsFileId')
      at FileStoreStrategyFactory.getFileStrategy (models/lib/fileStoreStrategy.js:112)
      at detectStoredFileMime (models/lib/fileTypeCorrection.js:120)
      at FilesCollection.onAfterUpload (models/attachments.server.js:215)

`getFileStrategy` decided the storage like this:

  storage = fileObj.versions[versionName].storage;
  if (!storage) {
    if (fileObj.meta.source == "import" || fileObj.versions[versionName].meta.gridFsFileId) {

A freshly uploaded file has no `meta` on its version - only a GridFS one does -
so that last read threw on EVERY upload. onAfterUpload catches and logs, so the
upload itself succeeded and looked fine, while the two things that hook does were
silently skipped for every new file: detecting the real mime type and correcting
the stored filename from it. `fileObj.meta` can be absent the same way, and so
can the version itself when a caller asks for one this file does not have.

All three reads are defensive now, and the decision is unchanged where the data
is there: a stated storage wins, an explicit argument wins over that, an import
or a GridFS version is still GridFS, and everything else is the filesystem.

tests/fileTypeCorrection.test.cjs replays that decision table, including the
document shape from the log (a version with no meta), a missing version, and no
file object at all - and fails if the unguarded read comes back.

Thanks to xet7 !
2026-07-27 21:39:51 +03:00
..
2026-05-03 18:36:15 +03:00
2026-07-05 09:30:12 +03:00
2026-06-12 20:15:56 +03:00