Skip to content

Commit

Permalink
Cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
anudit committed Sep 11, 2021
1 parent aa8e141 commit 52aaf8e
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 80 deletions.
3 changes: 3 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
"@/contexts/*": [
"contexts/*"
],
"@/middlewares/*": [
"middlewares/*"
],
}
},
"exclude": [
Expand Down
12 changes: 6 additions & 6 deletions next-sitemap.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
siteUrl: 'https://theconvo.space',
changefreq: 'daily',
priority: 0.7,
sitemapSize: 5000,
generateRobotsTxt: true,
}
siteUrl: 'https://theconvo.space',
changefreq: 'daily',
priority: 0.7,
sitemapSize: 5000,
generateRobotsTxt: true,
}
2 changes: 1 addition & 1 deletion pages/api/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isAddress, verifyMessage } from 'ethers/lib/utils';
import nacl from 'tweetnacl';
const { Crypto } = require("@peculiar/webcrypto");

import withApikey from 'middlewares/withApikey';
import withApikey from "@middlewares/withApikey";

async function validateNearSignature(data, signature, signerAddress){
const tokenMessage = new TextEncoder().encode(data);
Expand Down
2 changes: 1 addition & 1 deletion pages/api/comment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getComment } from "@/lib/thread-db";
import withApikey from "middlewares/withApikey";
import withApikey from "@middlewares/withApikey";

const handler = async(req, res) => {

Expand Down
18 changes: 4 additions & 14 deletions pages/api/comments.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import validateAuth from "@/lib/validateAuth";
import { createComment, deleteComment, getComments } from "@/lib/thread-db";
import { Where } from "@textile/hub";
import withApikey from "@middlewares/withApikey";

function isValidUrl(string) {
let url;
Expand All @@ -14,20 +15,7 @@ function isValidUrl(string) {
return url.protocol === "http:" || url.protocol === "https:";
}

export default async (req, res) => {

// Required for CORS/Pre-flight Check.
if (req.method === 'OPTIONS') {
return res.status(200).end();
}

// Validate API Key
if (Object.keys(req.query).includes('apikey') === false || req.query.apikey !== 'CONVO' ){
return res.status(401).json({
'success': false,
'error': 'Invalid API key, please refer to the integration docs at https://docs.theconvo.space/ to see how to get and use a new API key.'
});
}
const handler = async(req, res) => {

try {

Expand Down Expand Up @@ -211,3 +199,5 @@ export default async (req, res) => {
return res.status(500).json({ success: false,'error':error.toString() });
}
}

export default withApikey(handler);
12 changes: 4 additions & 8 deletions pages/api/custom/lb.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { getTrustScores } from "@/lib/thread-db";
import withApikey from "@/middlewares/withApikey";

export default async (req, res) => {

if (Object.keys(req.query).includes('apikey') === false || req.query.apikey !== 'CONVO' ){
return res.status(401).json({
'success':false,
'error': 'Invalid API key, please refer to the integration docs at https://docs.theconvo.space/ to see how to get and use a new API key.'
});
}
const handler = async(req, res) => {

try {

Expand Down Expand Up @@ -38,3 +32,5 @@ export default async (req, res) => {
return res.status(500).json({ 'success': false, error });
}
}

export default withApikey(handler)
17 changes: 4 additions & 13 deletions pages/api/getAblyAuth.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
import Ably from "ably/promises";
import withApikey from "@middlewares/withApikey";

export default async function handler(req, res) {

if (req.method === 'OPTIONS') {
return res.status(200).end();
}

if (Object.keys(req.query).includes('apikey') === false || req.query.apikey !== 'CONVO' ){
return res.status(401).json({
'success':false,
'error': 'Invalid API key, please refer to the integration docs at https://docs.theconvo.space/ to see how to get and use a new API key.'
});
}

const handler = async(req, res) => {

const client = new Ably.Realtime(process.env.ABLY_SUBSCRIBE_API_KEY);
const tokenRequestData = await client.auth.createTokenRequest({ clientId: 'convo' });
res.status(200).json(tokenRequestData);
}

export default withApikey(handler)
17 changes: 5 additions & 12 deletions pages/api/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Where , ThreadID} from '@textile/hub';
import { ethers } from "ethers";
import { getAddress, isAddress } from 'ethers/lib/utils';
import fetcher from '@/utils/fetcher';
import withApikey from "@/middlewares/withApikey";

async function calculateScore(address) {
let tp = new ethers.providers.AlchemyProvider("mainnet","hHgRhUVdMTMcG3_gezsZSGAi_HoK43cA");
Expand Down Expand Up @@ -144,18 +145,7 @@ async function setCache(address, scoreData) {
}]);
}

export default async (req, res) => {

if (req.method === 'OPTIONS') {
return res.status(200).end();
}

if (Object.keys(req.query).includes('apikey') === false || req.query.apikey !== 'CONVO' ){
return res.status(401).json({
'success': false,
'error': 'Invalid API key, please refer to the integration docs at https://docs.theconvo.space/ to see how to get and use a new API key.'
});
}
const handler = async(req, res) => {

try {

Expand Down Expand Up @@ -218,3 +208,6 @@ export default async (req, res) => {
return res.status(500).json({ 'success': false, error });
}
}


export default withApikey(handler)
17 changes: 5 additions & 12 deletions pages/api/threads.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import { getThread, getThreads, getAllThreads } from "@/lib/thread-db";
import withApikey from "@/middlewares/withApikey";

export default async (req, res) => {

if (req.method === 'OPTIONS') {
return res.status(200).end();
}

if (Object.keys(req.query).includes('apikey') === false || req.query.apikey !== 'CONVO' ){
return res.status(401).json({
'success':false,
'error': 'Invalid API key, please refer to the integration docs at https://docs.theconvo.space/ to see how to get and use a new API key.'
});
}
const handler = async(req, res) => {

try {

Expand All @@ -32,3 +22,6 @@ export default async (req, res) => {
return res.status(500).json({ 'success': false, error });
}
}


export default withApikey(handler)
16 changes: 4 additions & 12 deletions pages/api/validateAuth.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import withApikey from '@/middlewares/withApikey';
import jwt from 'jsonwebtoken'

export default async (req, res) => {

if (req.method === 'OPTIONS') {
return res.status(200).end();
}

if (Object.keys(req.query).includes('apikey') === false || req.query.apikey !== 'CONVO' ){
return res.status(401).json({
'success': false,
'error': 'Invalid API key, please refer to the integration docs at https://docs.theconvo.space/ to see how to get and use a new API key.'
});
}
const handler = async(req, res) => {

try {

Expand Down Expand Up @@ -61,3 +51,5 @@ export default async (req, res) => {

}
}

export default withApikey(handler)
5 changes: 4 additions & 1 deletion pages/api/vote.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import validateAuth from "@/lib/validateAuth";
import { toggleUpvote, toggleDownvote } from "@/lib/thread-db";
import withApikey from "@/middlewares/withApikey";

export default async (req, res) => {
const handler = async(req, res) => {

if (req.method === 'OPTIONS') {
return res.status(200).end();
Expand Down Expand Up @@ -72,3 +73,5 @@ export default async (req, res) => {

}
}

export default withApikey(handler);

0 comments on commit 52aaf8e

Please sign in to comment.