Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ PORT=3001
STEEMJS_URL=https://api.steemit.com
DEFAULT_REDIRECT_URI=https://steemit.com/login.html#account={{username}}
REACT_DISABLE_ACCOUNT_CREATION=false
ANALYTICS_UPDATE_SUPERKEY=123456
INTERNAL_API_TOKEN=xxxx
PENDING_CLAIMED_ACCOUNTS_THRESHOLD=100
COUNTRY_CODE=cn
Expand Down
32 changes: 32 additions & 0 deletions db/migrations/20260603120000-drop-analytics.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

module.exports = {
up: async (queryInterface) => {
await queryInterface.dropTable('analytics');
},

down: async (queryInterface, Sequelize) => {
await queryInterface.createTable('analytics', {
id: {
type: Sequelize.INTEGER,
allowNull: false,
autoIncrement: true,
primaryKey: true,
},
event_id: {
allowNull: false,
type: Sequelize.INTEGER,
},
total: {
type: Sequelize.INTEGER,
allowNull: false,
},
created_at: {
allowNull: false,
type: Sequelize.DATE,
},
});
await queryInterface.addIndex('analytics', { fields: ['event_id'] });
await queryInterface.addIndex('analytics', { fields: ['created_at'] });
},
};
11 changes: 0 additions & 11 deletions db/models/analytics.js

This file was deleted.

12 changes: 6 additions & 6 deletions db/models/index.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import Sequelize, { DataTypes } from 'sequelize';
import { readFileSync } from "fs";
import { readFileSync } from 'fs';
import { getLogChild } from '../../helpers/logger.js';
import common, { getEnv } from '../../helpers/common.js';
import actions from './actions.js';
import analytics from './analytics.js';
import config from './config.js';
import emailcode from './emailcode.js';
import phonecode from './phonecode.js';
import users from './users.js';

const __dirname = common.getDirnameByUrl(import.meta.url);
const allConfig = JSON.parse(readFileSync(`${__dirname}/../config/config.json`));
const allConfig = JSON.parse(
readFileSync(`${__dirname}/../config/config.json`)
);
const env = getEnv('DATABASE_NAME') || 'development';
const logger = getLogChild({ module: 'db' });
const dbConfig = allConfig[env];
dbConfig.logging = function(msg) {
dbConfig.logging = function (msg) {
logger.debug(msg);
};

const sequelize = new Sequelize(getEnv(dbConfig.use_env_variable), dbConfig);
const modelsHelpers = {
actions,
analytics,
config,
emailcode,
phonecode,
users,
};
const db = {};

Object.keys(modelsHelpers).forEach(function(modelName) {
Object.keys(modelsHelpers).forEach(function (modelName) {
db[modelName] = modelsHelpers[modelName](sequelize, DataTypes);
if (db[modelName].associate) {
db[modelName].associate(db);
Expand Down
33 changes: 6 additions & 27 deletions helpers/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,6 @@ export const updateUsers = async (data, where) => db.users.update(data, where);

export const query = async (q, options) => db.sequelize.query(q, options);

export const findAnalyticsLog = async (where) => db.analytics.findAll(where);
export const createAnalyticsLog = async (where, data) =>
db.analytics.findOrCreate({ where, defaults: data });

export const updateAnalytics = async (where, data, increase = false) => {
const result = await createAnalyticsLog(where, data);
if (result[1] === false) {
// find exist data
if (increase === true) {
result[0].total += 1;
await result[0].save();
} else {
result[0].total = data.total;
await result[0].save();
}
}
return true;
};

export const createEmailRecord = async (data) => db.emailcode.create(data);
export const findEmailRecord = async (where) => db.emailcode.findOne(where);
export const createPhoneRecord = async (data) => db.phonecode.create(data);
Expand Down Expand Up @@ -234,7 +215,11 @@ export function clearConfigCache(key) {
* Returns default ['gmail.com'] if config not found or parse fails
*/
export async function getWhiteEmailDomain() {
const domains = await getConfigValue('white_email_domain', ['gmail.com'], 300);
const domains = await getConfigValue(
'white_email_domain',
['gmail.com'],
300
);
return Array.isArray(domains) ? domains : ['gmail.com'];
}

Expand All @@ -243,11 +228,7 @@ export async function getWhiteEmailDomain() {
* Returns default [] if config not found or parse fails
*/
export async function getPrivateWhiteEmailDomain() {
const domains = await getConfigValue(
'private_white_email_domain',
[],
300
);
const domains = await getConfigValue('private_white_email_domain', [], 300);
return Array.isArray(domains) ? domains : [];
}

Expand All @@ -264,8 +245,6 @@ export default {
phoneIsInUse,
updateUsers,
query,
findAnalyticsLog,
updateAnalytics,
createEmailRecord,
findEmailRecord,
actionLimitNew,
Expand Down
3 changes: 0 additions & 3 deletions routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,4 @@ router.post('/create_user', apiMiddleware(apiHandlers.finalizeSignup));

router.post('/create_account', apiMiddleware(apiHandlers.handleCreateAccount));

// This api is a temporary api. This will be removed in the future!
router.get('/analytics', apiMiddleware(apiHandlers.handleAnalytics));

export default router;
71 changes: 0 additions & 71 deletions routes/apiHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,76 +64,6 @@ async function handleGuessCountry(req) {
return { location: services.locationFromIp(req.ip) };
}

/**
* Collect the analytics data
*/
async function handleAnalytics(req) {
const { event_id, superkey, total, t } = req.query;
/**
* Temporary API.
*/
if (event_id < 1) {
throw new ApiError({
type: 'error_event_id',
status: 200,
});
}

// action limit
await database.logAction({
action: 'analytics',
ip: req.ip,
});
await database.actionLimit(req.ip);

if (superkey) {
// In super mode we can update `total` and `created_at` fields.
const SUPERKEY_ENV = getEnv('ANALYTICS_UPDATE_SUPERKEY');
if (!SUPERKEY_ENV) {
throw new ApiError({
type: 'error_analytics_update_superkey_not_set',
status: 200,
});
}
if (superkey !== SUPERKEY_ENV) {
throw new ApiError({
type: 'error_superkey',
status: 200,
});
}
const where = {
event_id,
created_at: `${t}T00:00:00Z`,
};
const data = {
total,
};
try {
await database.updateAnalytics(where, data);
} catch (error) {
req.log.error(error, 'Unable to store analytics data');
return { success: true };
}
} /* else {
// In normal mode we only update `total` by adding 1.
const today = new Date().toISOString().replace(/T.+/, '');
const where = {
event_id,
created_at: `${today}T00:00:00Z`,
};
const data = {
total: 1,
};
try {
await database.updateAnalytics(where, data, true);
} catch (error) {
req.log.error(error, 'Unable to store analytics data');
return { success: true };
}
} */
return { success: true };
}

async function handleRequestEmailCode(req) {
const ip = req.ip;
const email = req.body?.email;
Expand Down Expand Up @@ -1268,7 +1198,6 @@ export default {
handleCreateAccount,
handleCheckUsername,
handleGuessCountry,
handleAnalytics,
handleRequestEmailCode,
handleConfirmEmailCode,
finalizeSignup,
Expand Down
6 changes: 0 additions & 6 deletions src/utils/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,3 @@ export const getPendingClaimedAccounts = (callback) => {
}
});
};

export const updateAnalytics = (eventId) => {
fetch(`/api/analytics?event_id=${eventId}`)
.then(() => {})
.catch(() => {});
};
Loading