2019-05-17 04:11:10 +08:00
|
|
|
import Auth from '/imports/ui/services/auth';
|
2021-10-05 03:22:18 +08:00
|
|
|
import { makeCall } from '/imports/ui/services/api';
|
2019-05-17 04:11:10 +08:00
|
|
|
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-02-09 23:59:59 +08:00
|
|
|
let 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('&');
|
|
|
|
};
|
|
|
|
|
2021-10-05 03:22:18 +08:00
|
|
|
const getPadId = (locale) => makeCall('getPadId', locale);
|
|
|
|
|
|
|
|
const buildPadURL = (padId) => {
|
|
|
|
if (padId) {
|
|
|
|
const params = getPadParams();
|
|
|
|
const url = Auth.authenticateURL(`${NOTE_CONFIG.url}/p/${padId}?${params}`);
|
|
|
|
return url;
|
2019-05-17 04:11:10 +08:00
|
|
|
}
|
2021-10-05 03:22:18 +08:00
|
|
|
|
|
|
|
return null;;
|
2019-05-17 04:11:10 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
2021-10-05 03:22:18 +08:00
|
|
|
getPadId,
|
|
|
|
buildPadURL,
|
2019-05-17 04:11:10 +08:00
|
|
|
};
|