DEV Community

Cover image for Week 4 of Coding Period in GSoC
Amanjot Singh
Amanjot Singh

Posted on

Week 4 of Coding Period in GSoC

Week 4 was more focused on learning than coding. This week I got to start the task of removing CFS dependency from the project and replace it with another package. This task involved Frontend, Backend, and Database. Let's have a look at the week 4 development log.

I started exploring the package with which the existing CFS dependency could be replaced. The CFS dependency is now deprecated and we got to replace that with Meteor Files The package was recommended on README of CFS dependency. However, I looked for a more similar package that was folks of CFS.

Then, I started understanding the backend of OGV. I started learning backend stuff in Meteor and started replacing things one by one.

I updated the frontend to the way to save files from the frontend.

// Previous Code
function uploadFile(event) {
  FS.Utility.eachFile(event, file => {
    const fsFile = new FS.File(file);
    fsFile.owner = Meteor.userId();
    fsFile.converted = false;
    fsFile.timeUploaded = new Date();
    fsFile.about = `The model ${fsFile.name()} was uploaded on ${
      fsFile.timeUploaded
    }`;
    fsFile.viewsCount = 0;
    fsFile.conversion = 0;

    ModelFiles.insert(fsFile, err => {
      if (err) {
        sAlert.error(
          "There was some error in uploading your file, please try again/later"
        );
      } else {
        sAlert.success(
          "File Uploaded, and will appear in file manager after it's converted"
        );
        Router.go(`/processing/${fsFile._id}`);
      }
    });
  });
Enter fullscreen mode Exit fullscreen mode
// Latest Code with new package
function uploadFile(e, template) {
  console.log(template);
  if (e.currentTarget.files && e.currentTarget.files[0]) {
    let fsFile = e.currentTarget.files[0];
    fsFile.owner = Meteor.userId();
    fsFile.converted = false;
    fsFile.timeUploaded = new Date();
    fsFile.about = `The model ${fsFile.name} was uploaded on ${
      fsFile.timeUploaded
    }`;
    fsFile.viewsCount = 0;
    fsFile.conversion = 0;
    // We upload only one file, in case
    // multiple files were selected
    const upload = ModelFiles.insert(
      {
        file: fsFile,
        chunkSize: "dynamic"
      },
      false
    );

    upload.on("start", function() {
      template.currentUpload.set(this);
    });

    upload.on("end", function(error, fileObj) {
      if (error) {
        alert(`Error during upload: ${error}`);
      } else {
        alert(`File "${fileObj.name}" successfully uploaded`);
        Router.go(`/processing/${fileObj._id}`);
      }
      // template.currentUpload.set(false);
    });

    upload.start();
  }
Enter fullscreen mode Exit fullscreen mode

As it was having a lot of breaking changes on the frontend, backend, and database. It was strenuous to migrate the package all at once. The achievements of this week were:

  • The files started uploading and saving on the local directory
  • Created Mongo Collection for the new package (Existing one could not be used)
  • Updated file upload code of Server-side and made the file details get saved on database
  • Read about the pub/sub in Meteor and how to use them efficiently

Top comments (0)