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

New feedback system #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 9 additions & 45 deletions lib/Nexus.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/Nexus.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/customErrors.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/customErrors.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/parameters.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/parameters.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nexusmods/nexus-api",
"version": "1.4.25",
"version": "1.5.1",
"main": "./lib/index.js",
"typings": "lib/index",
"homepage": "https://www.nexusmods.com/",
Expand Down
118 changes: 64 additions & 54 deletions src/Nexus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1239,60 +1239,70 @@ class Nexus {
if (message.length === 0) {
return Promise.reject(new Error('Feedback message can\'t be empty'));
}
return this.checkFileSize(fileBundle)
.then(() => new Promise<types.IFeedbackResponse>((resolve, reject) => {
const form = new FormData();
form.append("feedback_text", message);
form.append("feedback_title", title.substr(0, 255));

if (fileBundle !== undefined) {
form.append('feedback_file', fs.createReadStream(fileBundle));
}
if (groupingKey !== undefined) {
form.append('grouping_key', groupingKey);
}
if (id !== undefined) {
form.append('reference', id);
}
const headers = { ...this.mBaseData.headers, ...form.getHeaders() };

if (anonymous) {
delete headers['APIKEY'];
} else if (this.mOAuthCredentials !== undefined) {
headers['Authorization'] = `Bearer: ${this.mOAuthCredentials.token}`;
}

const inputUrl = anonymous
? `${param.API_URL}/feedbacks/anonymous`
: `${param.API_URL}/feedbacks`;

const req = lib(inputUrl).request({
...url.parse(inputUrl),
method: 'POST',
headers,
timeout: 30000,
}, (res: http.IncomingMessage) => {
res.setEncoding('utf8');
let rawData = '';
res
.on('data', (chunk) => { rawData += chunk; })
.on('error', err => {
return reject(err);
})
.on('end', () => {
if (res.statusCode >= 400) {
return reject(new HTTPError(res.statusCode, res.statusMessage, rawData, inputUrl));
} else {
return resolve(JSON.parse(rawData));
}
});
});

req.on('error', err => reject(err));

form.pipe(req);
// req.end();
}));
if (groupingKey) {
message = message.concat(`\n\nhash: ${groupingKey}`);
}
const encodedMessage = encodeURIComponent(message);
const encodedTitle = encodeURIComponent(title);
const ghURL = `https://github.com/Nexus-Mods/Vortex/issues/new?title=${encodedTitle}&body=${encodedMessage}`;
const { shell } = require('electron')
shell.openExternal(ghURL);
return Promise.resolve(undefined);

// return this.checkFileSize(fileBundle)
// .then(() => new Promise<types.IFeedbackResponse>((resolve, reject) => {
// const form = new FormData();
// form.append("feedback_text", message);
// form.append("feedback_title", title.substr(0, 255));

// if (fileBundle !== undefined) {
// form.append('feedback_file', fs.createReadStream(fileBundle));
// }
// if (groupingKey !== undefined) {
// form.append('grouping_key', groupingKey);
// }
// if (id !== undefined) {
// form.append('reference', id);
// }
// const headers = { ...this.mBaseData.headers, ...form.getHeaders() };

// if (anonymous) {
// delete headers['APIKEY'];
// } else if (this.mOAuthCredentials !== undefined) {
// headers['Authorization'] = `Bearer: ${this.mOAuthCredentials.token}`;
// }

// const inputUrl = anonymous
// ? `${param.API_URL}/feedbacks/anonymous`
// : `${param.API_URL}/feedbacks`;

// const req = lib(inputUrl).request({
// ...url.parse(inputUrl),
// method: 'POST',
// headers,
// timeout: 30000,
// }, (res: http.IncomingMessage) => {
// res.setEncoding('utf8');
// let rawData = '';
// res
// .on('data', (chunk) => { rawData += chunk; })
// .on('error', err => {
// return reject(err);
// })
// .on('end', () => {
// if (res.statusCode >= 400) {
// return reject(new HTTPError(res.statusCode, res.statusMessage, rawData, inputUrl));
// } else {
// return resolve(JSON.parse(rawData));
// }
// });
// });

// req.on('error', err => reject(err));

// form.pipe(req);
// // req.end();
// }));
}

//#endregion
Expand Down
Loading