Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade @upstash/redis to v1 #30

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions netlify/functions/spotify-callback/spotify-callback.ts
@@ -1,5 +1,5 @@
import { Handler } from '@netlify/functions';
import { auth, set } from '@upstash/redis';
import { Redis } from '@upstash/redis';
import { createCipheriv, createHash, randomBytes } from 'crypto';
import { request } from 'undici';

Expand Down Expand Up @@ -73,12 +73,10 @@ export const handler: Handler = async (event, context) => {
}

try {
auth(REDIS_URL, REDIS_WRITE_TOKEN);
const redis = new Redis({ url: REDIS_URL, token: REDIS_WRITE_TOKEN });
const encrypted = encrypt(bodyParsed['refresh_token']);
const { error } = await set(state, encrypted);
if (error) {
return errorResponse('Token set failed', { error });
}
await redis.set(state, encrypted);

return {
statusCode: 200,
body: `<script>
Expand Down
15 changes: 9 additions & 6 deletions netlify/functions/spotify-last-played/spotify-last-played.ts
@@ -1,4 +1,4 @@
import { auth, get, set } from '@upstash/redis';
import { Redis } from '@upstash/redis';
import { createDecipheriv, createHash } from 'crypto';
import { request } from 'undici';

Expand Down Expand Up @@ -101,22 +101,25 @@ exports.handler = async (event) => {
}

let songInfo = null;
auth(REDIS_URL, REDIS_WRITE_TOKEN);
const { data } = await get(`${username}###last`);
if (data != null && data !== '') {
const redis = new Redis({
url: REDIS_URL,
token: REDIS_WRITE_TOKEN,
});
const data = await redis.get(`${username}###last`);
if (data != null) {
return {
statusCode: 200,
headers: {
'Cache-Control': 'max-age=3600',
'Content-Type': 'application/json',
},
body: data,
body: JSON.stringify(data),
};
}
try {
songInfo = await getSongResponseDataWithRefreshToken(username);
if (songInfo != null) {
await set(`${username}###last`, JSON.stringify(songInfo));
await redis.set(`${username}###last`, songInfo);
return {
statusCode: 200,
headers: {
Expand Down