Dynamic Linking
Erstellt nun Dynamic links anstelle von normalen links
This commit is contained in:
parent
e9e746b044
commit
8aaefdc5e0
@ -16,7 +16,7 @@ app.set('view engine', 'ejs');
|
||||
app.use(logger('dev'));
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({
|
||||
extended: false
|
||||
extended: true
|
||||
}));
|
||||
app.use(express.static(path.join(__dirname, 'public')));
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
var push = require('../push/push');
|
||||
var axios = require('axios')
|
||||
const {
|
||||
query,
|
||||
nonQuery
|
||||
@ -452,13 +453,37 @@ async function verifyInvite(link, user_id) {
|
||||
|
||||
async function createInvite(sl_id) {
|
||||
try {
|
||||
let link = generateInviteLink();
|
||||
await nonQuery('UPDATE "Shoppinglist" SET invitelink = $1 WHERE sl_id = $2;', [link, sl_id]);
|
||||
let output = generateInviteLink(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) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//User manuell einladen
|
||||
async function manInvite(sl_id, uid) {
|
||||
try {
|
||||
@ -556,15 +581,14 @@ function items_in_groups(groups, items, sl_id, sl_admin, sl_members, name, descr
|
||||
}
|
||||
|
||||
//Create invite link for your own shoppinglist
|
||||
function generateInviteLink() {
|
||||
function generateInviteLink(actsl_id) {
|
||||
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
var output = "";
|
||||
|
||||
for (let i = 0; i < 50; i++) {
|
||||
output += possible.charAt(Math.floor(Math.random() * possible.length));
|
||||
}
|
||||
|
||||
return output;
|
||||
return output
|
||||
}
|
||||
|
||||
function users_to_array(admin, members) {
|
||||
|
@ -349,6 +349,7 @@ router.delete("/item", async (req, res) => {
|
||||
// Invite System
|
||||
|
||||
router.post("/invite", async (req, res) => {
|
||||
console.log("REQ BODY", req.body.sl_id)
|
||||
try {
|
||||
res.status(200).send(await postgres.createInvite(req.body.sl_id));
|
||||
} catch (err) {
|
||||
@ -405,7 +406,7 @@ router.post("/invitemember", (req, res) => {
|
||||
uid = decodedToken.uid;
|
||||
|
||||
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));
|
||||
} catch (err) {
|
||||
res.status(400).send(await err);
|
||||
|
Loading…
x
Reference in New Issue
Block a user