2019-05-17 04:11:10 +08:00
|
|
|
import Users from '/imports/api/users';
|
|
|
|
import Auth from '/imports/ui/services/auth';
|
|
|
|
import Settings from '/imports/ui/services/settings';
|
|
|
|
|
|
|
|
const NOTE_CONFIG = Meteor.settings.public.note;
|
|
|
|
|
|
|
|
const getLang = () => {
|
|
|
|
const { locale } = Settings.application;
|
|
|
|
return locale ? locale.toLowerCase() : '';
|
|
|
|
};
|
|
|
|
|
|
|
|
const getPadParams = () => {
|
2021-03-07 22:29:10 +08:00
|
|
|
const config = {};
|
2019-05-17 04:11:10 +08:00
|
|
|
config.lang = getLang();
|
2021-02-09 23:59:59 +08:00
|
|
|
config.rtl = document.documentElement.getAttribute('dir') === 'rtl';
|
2019-05-17 04:11:10 +08:00
|
|
|
|
|
|
|
const params = [];
|
2019-05-29 22:31:27 +08:00
|
|
|
Object.keys(config).forEach((k) => {
|
|
|
|
params.push(`${k}=${encodeURIComponent(config[k])}`);
|
|
|
|
});
|
|
|
|
|
2019-05-17 04:11:10 +08:00
|
|
|
return params.join('&');
|
|
|
|
};
|
|
|
|
|
|
|
|
const getPadURL = (padId, readOnlyPadId, ownerId) => {
|
|
|
|
const userId = Auth.userID;
|
2021-02-09 23:59:59 +08:00
|
|
|
const params = getPadParams();
|
2019-05-17 04:11:10 +08:00
|
|
|
let url;
|
|
|
|
if (!ownerId || (ownerId && userId === ownerId)) {
|
2019-05-29 22:31:27 +08:00
|
|
|
url = Auth.authenticateURL(`${NOTE_CONFIG.url}/p/${padId}?${params}`);
|
2019-05-17 04:11:10 +08:00
|
|
|
} else {
|
2021-02-09 23:59:59 +08:00
|
|
|
url = Auth.authenticateURL(`${NOTE_CONFIG.url}/p/${readOnlyPadId}?${params}`);
|
2019-05-17 04:11:10 +08:00
|
|
|
}
|
|
|
|
return url;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
getPadURL,
|
|
|
|
};
|