Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lutangar committed Oct 13, 2022
1 parent 04bea18 commit 5197e52
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
4 changes: 0 additions & 4 deletions api/constants/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const DEFAULT_LANG = 'en-US';
const DEFAULT_CELL_SIZE = 'medium';
const DEFAULT_GA_VIEW = '162469865';
const MOBILE_GA_VIEW = '205673218';
const DEFAULT_FORMAT = 'cboard';
const APP_LANGS = [
'ar-SA',
Expand Down Expand Up @@ -51,6 +49,4 @@ module.exports = {
DEFAULT_CELL_SIZE: DEFAULT_CELL_SIZE,
APP_LANGS: APP_LANGS,
DEFAULT_FORMAT: DEFAULT_FORMAT,
DEFAULT_GA_VIEW: DEFAULT_GA_VIEW,
MOBILE_GA_VIEW: MOBILE_GA_VIEW
};
8 changes: 6 additions & 2 deletions api/controllers/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const { google } = require('googleapis');
const analyticsreporting = google.analyticsreporting('v4');
const constants = require('../constants');
const config = require("../../config");

module.exports = {
batchGet: batchGet,
Expand All @@ -20,7 +21,7 @@ async function batchGet(req, res) {
try {
const reportRequests = req.body.map(requestReport => {
const report = {
viewId: requestReport.mobileView ? constants.MOBILE_GA_VIEW : constants.DEFAULT_GA_VIEW,
viewId: requestReport.mobileView ? config.MOBILE_GA_VIEW : config.DEFAULT_GA_VIEW,
dateRanges: [
{
startDate: requestReport.startDate,
Expand Down Expand Up @@ -99,4 +100,7 @@ async function userActivity(req, res) {
}
}

gapiAuth();

if (config.MOBILE_GA_VIEW || config.DEFAULT_GA_VIEW) {
gapiAuth();
}
18 changes: 16 additions & 2 deletions api/helpers/blob.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
const uuidv1 = require('uuid/v1');
const azure = require('azure-storage');
const blobService = azure.createBlobService(
const fs = require('fs').promises;
const path = require('path');

const fileSystemBlobService = {
createContainerIfNotExists: async (shareName) => {
await fs.mkdir(path.resolve('uploads', shareName));
return Promise.resolve()
},
createBlockBlobFromText: (containerName, finalName,
buffer,
options, callback) => callback(),
getUrl: (container, name) => `${container}/${name}`
}

const blobService = process.env.AZURE_STORAGE_CONNECTION_STRING ? azure.createBlobService(
process.env.AZURE_STORAGE_CONNECTION_STRING
);
) : fileSystemBlobService;

module.exports = {
createBlockBlobFromText
Expand Down
15 changes: 10 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ const session = require('express-session');
const MongoStore = require('connect-mongo')(session);
const User = require('./api/models/User');
const Facebook = require('./api/passport/facebook');
const Google = require('./api/passport/google');
const GoogleToken = require('./api/passport/googleToken');
const FacebookToken = require('./api/passport/facebookToken');
const morgan = require('morgan');
const config = require('./config');
Expand Down Expand Up @@ -105,7 +103,7 @@ swaggerTools.initializeMiddleware(swaggerConfig, async function (middleware) {
})
})
);

const routerConfig = {
controllers: './api/controllers',
useStubs: false,
Expand All @@ -119,8 +117,15 @@ swaggerTools.initializeMiddleware(swaggerConfig, async function (middleware) {
app.enable('trust proxy')

Facebook.configureFacebookStrategy(app);
Google.configureGoogleStrategy(app);
GoogleToken.configureGoogleTokenStrategy(app);

if (config.google?.APP_ID) {
const Google = require('./api/passport/google');
const GoogleToken = require('./api/passport/googleToken');

Google.configureGoogleStrategy(app);
GoogleToken.configureGoogleTokenStrategy(app);
}

FacebookToken.configureFacebookTokenStrategy(app);
startServer(app);
});
Expand Down
Empty file added uploads/.gitkeep
Empty file.

0 comments on commit 5197e52

Please sign in to comment.