2022-10-11 17:32:28 +03:00
|
|
|
class AudienceFeedbackService {
|
2022-10-14 17:12:17 +03:00
|
|
|
/** @type URL */
|
|
|
|
#baseURL;
|
2022-10-19 14:21:43 +03:00
|
|
|
/** @type {Object} */
|
|
|
|
#urlService;
|
2022-10-14 17:12:17 +03:00
|
|
|
/**
|
|
|
|
* @param {object} deps
|
|
|
|
* @param {object} deps.config
|
|
|
|
* @param {URL} deps.config.baseURL
|
2022-10-19 14:21:43 +03:00
|
|
|
* @param {object} deps.urlService
|
2022-10-14 17:12:17 +03:00
|
|
|
*/
|
|
|
|
constructor(deps) {
|
|
|
|
this.#baseURL = deps.config.baseURL;
|
2022-10-19 14:21:43 +03:00
|
|
|
this.#urlService = deps.urlService;
|
2022-10-14 17:12:17 +03:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @param {string} uuid
|
|
|
|
* @param {string} postId
|
|
|
|
* @param {0 | 1} score
|
2024-07-29 23:49:40 +03:00
|
|
|
* @param {string} key - hashed uuid value
|
2022-10-14 17:12:17 +03:00
|
|
|
*/
|
2024-07-29 23:49:40 +03:00
|
|
|
buildLink(uuid, postId, score, key) {
|
2022-10-19 14:21:43 +03:00
|
|
|
let postUrl = this.#urlService.getUrlByResourceId(postId, {absolute: true});
|
|
|
|
|
|
|
|
if (postUrl.match(/\/404\//)) {
|
|
|
|
postUrl = this.#baseURL;
|
|
|
|
}
|
|
|
|
const url = new URL(postUrl);
|
2024-07-29 23:49:40 +03:00
|
|
|
url.hash = `#/feedback/${postId}/${score}/?uuid=${encodeURIComponent(uuid)}&key=${encodeURIComponent(key)}`;
|
2022-10-14 17:12:17 +03:00
|
|
|
return url;
|
2022-10-11 17:32:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = AudienceFeedbackService;
|