mirror of
https://github.com/wekan/wekan.git
synced 2025-12-20 09:20:12 +01:00
Support WRITEABLE_PATH envrionemnt variable
This commit is contained in:
parent
1cddd607ec
commit
a4732bacce
3 changed files with 30 additions and 26 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
import { Meteor } from 'meteor/meteor';
|
import { Meteor } from 'meteor/meteor';
|
||||||
import { FilesCollection } from 'meteor/ostrio:files';
|
import { FilesCollection } from 'meteor/ostrio:files';
|
||||||
|
import path from 'path';
|
||||||
import { createBucket } from './lib/grid/createBucket';
|
import { createBucket } from './lib/grid/createBucket';
|
||||||
import { createOnAfterUpload } from './lib/fsHooks/createOnAfterUpload';
|
import { createOnAfterUpload } from './lib/fsHooks/createOnAfterUpload';
|
||||||
import { createInterceptDownload } from './lib/fsHooks/createInterceptDownload';
|
import { createInterceptDownload } from './lib/fsHooks/createInterceptDownload';
|
||||||
|
|
@ -32,6 +33,12 @@ Attachments = new FilesCollection({
|
||||||
debug: false, // Change to `true` for debugging
|
debug: false, // Change to `true` for debugging
|
||||||
collectionName: 'attachments',
|
collectionName: 'attachments',
|
||||||
allowClientCode: true,
|
allowClientCode: true,
|
||||||
|
storagePath() {
|
||||||
|
if (process.env.WRITABLE_PATH) {
|
||||||
|
return path.join(process.env.WRITABLE_PATH, 'uploads', 'attachments');
|
||||||
|
}
|
||||||
|
return path.normalize(`assets/app/uploads/${this.collectionName}`);
|
||||||
|
},
|
||||||
onAfterUpload: function onAfterUpload(fileRef) {
|
onAfterUpload: function onAfterUpload(fileRef) {
|
||||||
createOnAfterUpload(attachmentBucket).call(this, fileRef);
|
createOnAfterUpload(attachmentBucket).call(this, fileRef);
|
||||||
// If the attachment doesn't have a source field
|
// If the attachment doesn't have a source field
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { Meteor } from 'meteor/meteor';
|
import { Meteor } from 'meteor/meteor';
|
||||||
import { FilesCollection } from 'meteor/ostrio:files';
|
import { FilesCollection } from 'meteor/ostrio:files';
|
||||||
|
import path from 'path';
|
||||||
import { createBucket } from './lib/grid/createBucket';
|
import { createBucket } from './lib/grid/createBucket';
|
||||||
import { createOnAfterUpload } from './lib/fsHooks/createOnAfterUpload';
|
import { createOnAfterUpload } from './lib/fsHooks/createOnAfterUpload';
|
||||||
import { createInterceptDownload } from './lib/fsHooks/createInterceptDownload';
|
import { createInterceptDownload } from './lib/fsHooks/createInterceptDownload';
|
||||||
|
|
@ -14,6 +15,12 @@ Avatars = new FilesCollection({
|
||||||
debug: false, // Change to `true` for debugging
|
debug: false, // Change to `true` for debugging
|
||||||
collectionName: 'avatars',
|
collectionName: 'avatars',
|
||||||
allowClientCode: true,
|
allowClientCode: true,
|
||||||
|
storagePath() {
|
||||||
|
if (process.env.WRITABLE_PATH) {
|
||||||
|
return path.join(process.env.WRITABLE_PATH, 'uploads', 'avatars');
|
||||||
|
}
|
||||||
|
return path.normalize(`assets/app/uploads/${this.collectionName}`);;
|
||||||
|
},
|
||||||
onBeforeUpload(file) {
|
onBeforeUpload(file) {
|
||||||
if (file.size <= 72000 && file.type.startsWith('image/')) {
|
if (file.size <= 72000 && file.type.startsWith('image/')) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
import { TAPi18n } from '/imports/i18n';
|
import { TAPi18n } from '/imports/i18n';
|
||||||
import AccountSettings from '../models/accountSettings';
|
import AccountSettings from '../models/accountSettings';
|
||||||
import TableVisibilityModeSettings from '../models/tableVisibilityModeSettings';
|
import TableVisibilityModeSettings from '../models/tableVisibilityModeSettings';
|
||||||
|
|
@ -24,8 +26,6 @@ import Triggers from '../models/triggers';
|
||||||
import UnsavedEdits from '../models/unsavedEdits';
|
import UnsavedEdits from '../models/unsavedEdits';
|
||||||
import Users from '../models/users';
|
import Users from '../models/users';
|
||||||
|
|
||||||
const fs = require('fs');
|
|
||||||
|
|
||||||
// Anytime you change the schema of one of the collection in a non-backward
|
// Anytime you change the schema of one of the collection in a non-backward
|
||||||
// compatible way you have to write a migration in this file using the following
|
// compatible way you have to write a migration in this file using the following
|
||||||
// API:
|
// API:
|
||||||
|
|
@ -1132,14 +1132,9 @@ Migrations.add('add-card-details-show-lists', () => {
|
||||||
|
|
||||||
Migrations.add('migrate-attachments-collectionFS-to-ostrioFiles', () => {
|
Migrations.add('migrate-attachments-collectionFS-to-ostrioFiles', () => {
|
||||||
AttachmentsOld.find().forEach(function(fileObj) {
|
AttachmentsOld.find().forEach(function(fileObj) {
|
||||||
//console.log('File: ', fileObj.userId);
|
|
||||||
|
|
||||||
// This directory must be writable on server, so a test run first
|
|
||||||
// We are going to copy the files locally, then move them to S3
|
|
||||||
const fileName = `./assets/app/uploads/attachments/${
|
|
||||||
fileObj._id
|
|
||||||
}-${fileObj.name()}`;
|
|
||||||
const newFileName = fileObj.name();
|
const newFileName = fileObj.name();
|
||||||
|
const storagePath = Attachments.storagePath({});
|
||||||
|
const filePath = path.join(storagePath, `${fileObj._id}-${newFileName}`);
|
||||||
|
|
||||||
// This is "example" variable, change it to the userId that you might be using.
|
// This is "example" variable, change it to the userId that you might be using.
|
||||||
const userId = fileObj.userId;
|
const userId = fileObj.userId;
|
||||||
|
|
@ -1149,19 +1144,19 @@ Migrations.add('migrate-attachments-collectionFS-to-ostrioFiles', () => {
|
||||||
const fileId = fileObj._id;
|
const fileId = fileObj._id;
|
||||||
|
|
||||||
const readStream = fileObj.createReadStream('attachments');
|
const readStream = fileObj.createReadStream('attachments');
|
||||||
const writeStream = fs.createWriteStream(fileName);
|
const writeStream = fs.createWriteStream(filePath);
|
||||||
|
|
||||||
writeStream.on('error', function(err) {
|
writeStream.on('error', function(err) {
|
||||||
console.log('Writing error: ', err, fileName);
|
console.log('Writing error: ', err, filePath);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Once we have a file, then upload it to our new data storage
|
// Once we have a file, then upload it to our new data storage
|
||||||
readStream.on('end', () => {
|
readStream.on('end', () => {
|
||||||
console.log('Ended: ', fileName);
|
console.log('Ended: ', filePath);
|
||||||
// UserFiles is the new Meteor-Files/FilesCollection collection instance
|
// UserFiles is the new Meteor-Files/FilesCollection collection instance
|
||||||
|
|
||||||
Attachments.addFile(
|
Attachments.addFile(
|
||||||
fileName,
|
filePath,
|
||||||
{
|
{
|
||||||
fileName: newFileName,
|
fileName: newFileName,
|
||||||
type: fileType,
|
type: fileType,
|
||||||
|
|
@ -1190,7 +1185,7 @@ Migrations.add('migrate-attachments-collectionFS-to-ostrioFiles', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
readStream.on('error', error => {
|
readStream.on('error', error => {
|
||||||
console.log('Error: ', fileName, error);
|
console.log('Error: ', filePath, error);
|
||||||
});
|
});
|
||||||
|
|
||||||
readStream.pipe(writeStream);
|
readStream.pipe(writeStream);
|
||||||
|
|
@ -1199,14 +1194,9 @@ Migrations.add('migrate-attachments-collectionFS-to-ostrioFiles', () => {
|
||||||
|
|
||||||
Migrations.add('migrate-avatars-collectionFS-to-ostrioFiles', () => {
|
Migrations.add('migrate-avatars-collectionFS-to-ostrioFiles', () => {
|
||||||
AvatarsOld.find().forEach(function(fileObj) {
|
AvatarsOld.find().forEach(function(fileObj) {
|
||||||
//console.log('File: ', fileObj.userId);
|
|
||||||
|
|
||||||
// This directory must be writable on server, so a test run first
|
|
||||||
// We are going to copy the files locally, then move them to S3
|
|
||||||
const fileName = `./assets/app/uploads/avatars/${
|
|
||||||
fileObj._id
|
|
||||||
}-${fileObj.name()}`;
|
|
||||||
const newFileName = fileObj.name();
|
const newFileName = fileObj.name();
|
||||||
|
const storagePath = Avatars.storagePath({});
|
||||||
|
const filePath = path.join(storagePath, `${fileObj._id}-${newFileName}`);
|
||||||
|
|
||||||
// This is "example" variable, change it to the userId that you might be using.
|
// This is "example" variable, change it to the userId that you might be using.
|
||||||
const userId = fileObj.userId;
|
const userId = fileObj.userId;
|
||||||
|
|
@ -1216,19 +1206,19 @@ Migrations.add('migrate-avatars-collectionFS-to-ostrioFiles', () => {
|
||||||
const fileId = fileObj._id;
|
const fileId = fileObj._id;
|
||||||
|
|
||||||
const readStream = fileObj.createReadStream('avatars');
|
const readStream = fileObj.createReadStream('avatars');
|
||||||
const writeStream = fs.createWriteStream(fileName);
|
const writeStream = fs.createWriteStream(filePath);
|
||||||
|
|
||||||
writeStream.on('error', function(err) {
|
writeStream.on('error', function(err) {
|
||||||
console.log('Writing error: ', err, fileName);
|
console.log('Writing error: ', err, filePath);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Once we have a file, then upload it to our new data storage
|
// Once we have a file, then upload it to our new data storage
|
||||||
readStream.on('end', () => {
|
readStream.on('end', () => {
|
||||||
console.log('Ended: ', fileName);
|
console.log('Ended: ', filePath);
|
||||||
// UserFiles is the new Meteor-Files/FilesCollection collection instance
|
// UserFiles is the new Meteor-Files/FilesCollection collection instance
|
||||||
|
|
||||||
Avatars.addFile(
|
Avatars.addFile(
|
||||||
fileName,
|
filePath,
|
||||||
{
|
{
|
||||||
fileName: newFileName,
|
fileName: newFileName,
|
||||||
type: fileType,
|
type: fileType,
|
||||||
|
|
@ -1273,7 +1263,7 @@ Migrations.add('migrate-avatars-collectionFS-to-ostrioFiles', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
readStream.on('error', error => {
|
readStream.on('error', error => {
|
||||||
console.log('Error: ', fileName, error);
|
console.log('Error: ', filePath, error);
|
||||||
});
|
});
|
||||||
|
|
||||||
readStream.pipe(writeStream);
|
readStream.pipe(writeStream);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue