Skip to content

Commit

Permalink
Fix ?
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoGresse committed Feb 1, 2024
1 parent 0df83a6 commit 0ee0cb9
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 17 deletions.
10 changes: 5 additions & 5 deletions functions/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@types/qs": "^6.9.4",
"firebase-functions-test": "^0.1.6",
"tslint": "^5.12.0",
"typescript": "^3.2.2"
"typescript": "^5.3.3"
},
"private": true
}
2 changes: 2 additions & 0 deletions functions/src/callable/getUpcomingEventsManually.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ export const getUpcomingEventManually = functions.https.onCall(
await assertOrganizationAdmins(context, data.organizationId)

const icals: Ical[] = []

const ical = await getIcal(data.icalId)
if (ical) {
icals.push(ical)
}

const icalsDatas = await getIcalFiles(icals)
return getUpcomingEvents(icalsDatas)
}
Expand Down
23 changes: 22 additions & 1 deletion functions/src/eventUpdater/getIcalFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,28 @@ const getIcalFiles = async (icals: Ical[]): Promise<IcalFile[]> => {
const icalFiles: IcalFile[] = []
for (const ical of icals) {
try {
const data = await fetch(ical.url).then(res => res.text())
const response = await fetch(ical.url, {
headers: {
Cookie: 'MEETUP_MEMBER=id=184681297; ',
},
})

console.log(
'response',
response.status,
response.statusText,
response.ok
)
if (!response.ok) {
throw new Error(
'Error fetching ical: ' +
response.status +
' ' +
response.statusText
)
}

const data = await response.text()

icalFiles.push({
data,
Expand Down
25 changes: 16 additions & 9 deletions functions/src/https/slackOauthRedirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,43 @@ import { db, serverTimestamp } from '../utils/initFirebase'
import { OrganizationId } from '../types/Organization'

export const slackOauthRedirect = functions.https.onRequest(
async (request, response) => {
async (request, response): Promise<void> => {
const { slack } = functions.config()

if (!slack || !slack.client_id || !slack.client_secret) {
console.error(
'Missing slack credentials (client_id or client_secret)'
)
return response.status(501).send('Missing slack credentials')
response.status(501).send('Missing slack credentials')
return
}

if (request.method !== 'GET') {
console.error(
'Got unsupported ${request.method} request. Expected GET.'
)
return response.status(405).send('Only GET requests are accepted')
response.status(405).send('Only GET requests are accepted')
return
}

// SSL_CHECK by slack to confirm SSL cert
if (request.query && request.query.ssl_check === '1') {
console.log('Confirmed SSL Cert')
return response.status(200).send()
response.status(200).send()
return
}

// @ts-ignore
if (!request.query && !request.query.code && !request.query.status) {
return response.status(401).send("Missing query attribute 'code'")
response.status(401).send("Missing query attribute 'code'")
return
}

const [organizationId] = request.query.state.split(',')

if (!organizationId) {
return response.status(401).send('Missing required attribute')
response.status(401).send('Missing required attribute')
return
}

const params = new URLSearchParams()
Expand All @@ -55,12 +60,13 @@ export const slackOauthRedirect = functions.https.onRequest(

if (!result.ok) {
console.error('The request was not ok: ' + JSON.stringify(result))
return response
response
.header(
'Location',
`https://${process.env.GCLOUD_PROJECT}.web.app`
)
.send(302)
return
}

const slackResultData = await result.json()
Expand All @@ -69,12 +75,13 @@ export const slackOauthRedirect = functions.https.onRequest(
slackResultData
)

return response
response
.header(
'Location',
`https://${process.env.GCLOUD_PROJECT}.web.app/slackResult?slackInstallId=${installId}`
)
.sendStatus(302)
return
}
)

Expand Down Expand Up @@ -105,5 +112,5 @@ export const saveNewInstallation = async (
createdAt: serverTimestamp(),
organizationId,
})
.then(ref => ref.id)
.then((ref) => ref.id)
}
2 changes: 1 addition & 1 deletion src/utils/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const serverTimestamp = firebase.firestore.FieldValue.serverTimestamp
export const nowTimestamp = firebase.firestore.Timestamp.now
export const deleteField = firebase.firestore.FieldValue.delete

// firebase.functions().useFunctionsEmulator('http://localhost:5000')
firebase.functions().useFunctionsEmulator('http://localhost:5000')
export const functions = {
getUpcomingEventManually: firebase
.functions()
Expand Down

0 comments on commit 0ee0cb9

Please sign in to comment.