Dynamic Linking

Erstellt nun Dynamic links anstelle von normalen links
This commit is contained in:
Georg Reisinger 2019-03-25 19:30:22 +01:00
parent e9e746b044
commit 8aaefdc5e0
3 changed files with 33 additions and 8 deletions

View File

@ -16,7 +16,7 @@ app.set('view engine', 'ejs');
app.use(logger('dev')); app.use(logger('dev'));
app.use(express.json()); app.use(express.json());
app.use(express.urlencoded({ app.use(express.urlencoded({
extended: false extended: true
})); }));
app.use(express.static(path.join(__dirname, 'public'))); app.use(express.static(path.join(__dirname, 'public')));

View File

@ -1,4 +1,5 @@
var push = require('../push/push'); var push = require('../push/push');
var axios = require('axios')
const { const {
query, query,
nonQuery nonQuery
@ -452,13 +453,37 @@ async function verifyInvite(link, user_id) {
async function createInvite(sl_id) { async function createInvite(sl_id) {
try { try {
let link = generateInviteLink(); let output = generateInviteLink(sl_id);
await nonQuery('UPDATE "Shoppinglist" SET invitelink = $1 WHERE sl_id = $2;', [link, sl_id]); var link;
axios({
method: 'POST',
url: 'https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=AIzaSyCuvwf78cmSDoZ2yS4XxHZhnjUn7yIHYfw',
data: {
"dynamicLinkInfo": {
"domainUriPrefix": "https://invite.dergeorg.at/invite",
"link": "https://smartshopper.cf/invite/" + output+"?slid="+sl_id,
"androidInfo": {
"androidPackageName": "at.smartshopper.smartshopperapp"
}
}
}
})
.then(async function(result) {
console.log("ShortLink: ", result.data.shortLink);
link = result.data.shortLink;
link= link.replace("https://invite.dergeorg.at/invite/", "");
console.log("generated link: ", link, " \nSL_id ", sl_id)
await nonQuery('UPDATE "Shoppinglist" SET invitelink = $1, dynamiclink = $2 WHERE sl_id = $3;', [output, link, sl_id]);
return result.data.shortLink;
})
.catch(err => console.error(err));
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} }
} }
//User manuell einladen //User manuell einladen
async function manInvite(sl_id, uid) { async function manInvite(sl_id, uid) {
try { try {
@ -555,16 +580,15 @@ function items_in_groups(groups, items, sl_id, sl_admin, sl_members, name, descr
return result; return result;
} }
//Create invite link for your own shoppinglist //Create invite link for your own shoppinglist
function generateInviteLink() { function generateInviteLink(actsl_id) {
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var output = ""; var output = "";
for (let i = 0; i < 50; i++) { for (let i = 0; i < 50; i++) {
output += possible.charAt(Math.floor(Math.random() * possible.length)); output += possible.charAt(Math.floor(Math.random() * possible.length));
} }
return output
return output;
} }
function users_to_array(admin, members) { function users_to_array(admin, members) {

View File

@ -349,6 +349,7 @@ router.delete("/item", async (req, res) => {
// Invite System // Invite System
router.post("/invite", async (req, res) => { router.post("/invite", async (req, res) => {
console.log("REQ BODY", req.body.sl_id)
try { try {
res.status(200).send(await postgres.createInvite(req.body.sl_id)); res.status(200).send(await postgres.createInvite(req.body.sl_id));
} catch (err) { } catch (err) {
@ -405,7 +406,7 @@ router.post("/invitemember", (req, res) => {
uid = decodedToken.uid; uid = decodedToken.uid;
try { try {
console.log("Route LInk inv", req.body.link); console.log("Route Link inv: ", req.body.link);
res.status(200).send(await postgres.verifyInvite(req.body.link, uid)); res.status(200).send(await postgres.verifyInvite(req.body.link, uid));
} catch (err) { } catch (err) {
res.status(400).send(await err); res.status(400).send(await err);