Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(marxan-runner): pipe assets to input files #293

Merged
merged 2 commits into from
Jun 30, 2021

Conversation

kgajowy
Copy link
Contributor

@kgajowy kgajowy commented Jun 28, 2021

Substitute this line for a meaningful title for your changes

Overview

Please write a description. If the PR is hard to understand, provide a quick explanation of the code.

Designs

Link to the related design prototypes (if applicable)

Testing instructions

Please explain how to test the PR: ID of a dataset, steps to reach the feature, etc.

Feature relevant tickets

Link to the related task manager tickets


Checklist before submitting

  • Meaningful commits and code rebased on develop.
  • If this PR adds feature that should be tested for regressions when
    deploying to staging/production, please add brief testing instructions
    to the deploy checklist (docs/deployment-checklist.md)
  • Update CHANGELOG file

@vercel
Copy link

vercel bot commented Jun 28, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployments, click below or on the icon next to each commit.

marxan – ./app

🔍 Inspect: https://vercel.com/vizzuality1/marxan/AcsmGxqhqFMMWRpj96aND9Txhgwh
✅ Preview: https://marxan-git-feat-marxan-42-marxan-486-input-dat-2-vizzuality1.vercel.app

marxan-storybook – ./app

🔍 Inspect: https://vercel.com/vizzuality1/marxan-storybook/6inJbVoBaibdPEf9e6srL3Lj5cXT
✅ Preview: https://marxan-storybook-git-feat-marxan-42-marxan-4-e502de-vizzuality1.vercel.app

@kgajowy kgajowy force-pushed the feat/MARXAN-42-MARXAN-486-input-dat-2 branch from bff2cee to 609bbe9 Compare June 29, 2021 09:39
@kgajowy kgajowy marked this pull request as ready for review June 29, 2021 10:06
@kgajowy kgajowy requested review from hotzevzl and Dyostiq and removed request for Dyostiq June 29, 2021 10:06
Comment on lines 102 to 108
assetUrl: `http://localhost:3000/puvsp.dat`,
targetRelativeDestination: `input/puvsp.dat`,
},
{
name: `puvsp_sporder.dat`,
assetUrl: `http://localhost:3000/puvsp_sporder.dat`,
targetRelativeDestination: `input/puvsp_sporder.dat`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

puvspr* (missing the final r)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hotzevzl
image

could be but it was taken directly from marxan's example ; )

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kgajowy which warez site did you download this copy of Marxan from? 😛
they're listed as puvspr.dat and puvspr_sporder.dat in the manual - no big deal of course as we can name these files as we wish, but just noting this to keep to the defaults mentioned in the manual

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

constructor(private readonly httpService: HttpService) {}

async include(directory: string, assets: Assets): Promise<void> {
// TODO security: ensure that none of the target filename starts with either `/` or `.` (tree traversing)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 22 to 38
return new Promise((resolve, reject) => {
const writer = createWriteStream(dest);
writer.on('finish', resolve);
writer.on('error', reject);
// "stream" seems to be broken, does not return stream but data itself
// https://github.com/nestjs/nest/issues/4144 - not really working
this.httpService
.get(sourceUri, {
responseType: 'stream',
})
.toPromise()
.then((response) => {
writer.write(response.data);
writer.end();
})
.catch(reject);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, so if stream does not work and it is not really streaming, why do you use createWriteStream? I'd suggest to just use writeFile

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought maybe someone can pinpoint some obvious thing I missed. :(

import { Injectable } from '@nestjs/common';
import { InputFiles } from '../../ports/input-files';
import { resolve, dirname } from 'path';
import { createWriteStream, promises } from 'fs';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import { createWriteStream, promises as fsPromises } from 'fs';

promises.mkdir is surprising a bit :)

Comment on lines 9 to 11
// asset: keyof Settings;
url: string;
relativeDestination: string; // this
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the comments 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import { Test, TestingModule } from '@nestjs/testing';
import { copySync } from 'fs-extra';
import AxiosMockAdapter from 'axios-mock-adapter';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd stick to use nock, it's library agnostic and a bit easier to use

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kgajowy kgajowy force-pushed the feat/MARXAN-42-MARXAN-486-input-dat-2 branch from 1d75fdc to 8e1814b Compare June 30, 2021 12:34
@kgajowy kgajowy merged commit 0ee774f into develop Jun 30, 2021
@kgajowy kgajowy deleted the feat/MARXAN-42-MARXAN-486-input-dat-2 branch June 30, 2021 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants