-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add new endpoints and improve tests * remove char * Fixes * fix name
- Loading branch information
1 parent
52f0b13
commit 1a47dce
Showing
14 changed files
with
12,472 additions
and
11,799 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import githubOctokitApi from '../github-octokit-api'; | ||
|
||
export const dynamic = 'force-dynamic'; | ||
|
||
/** | ||
* Trigger the GitHub Workflow responsible for capturing screenshots with | ||
* Checkly. | ||
* | ||
* @param {Request} request Request object. | ||
*/ | ||
export async function POST(request) { | ||
const url = request.nextUrl.searchParams.get('url'); | ||
try { | ||
new URL(url); // Throws an error if not a url. | ||
} catch (error) { | ||
return Response.json( | ||
{ error }, | ||
{ status: 403 } | ||
); | ||
} | ||
|
||
// @todo Abstract this for open sourcing. | ||
try { | ||
const response = await githubOctokitApi.request( | ||
'POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches', | ||
{ | ||
owner: 'penske-media-corp', | ||
repo: 'pmc-wayback-machine', | ||
workflow_id: 'capture-url.yml', | ||
ref: 'main', | ||
inputs: { | ||
url, | ||
}, | ||
headers: { | ||
'X-GitHub-Api-Version': '2022-11-28' | ||
} | ||
} | ||
); | ||
|
||
return Response.json({response}); | ||
} catch (error) { | ||
return Response.json( | ||
{error}, | ||
{ status: 403 } | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Octokit } from '@octokit/core'; | ||
|
||
// https://github.com/octokit/core.js#readme | ||
const octokit = new Octokit({ | ||
auth: process.env.GITHUB_TOKEN ?? '', | ||
}); | ||
|
||
export default octokit; |
16 changes: 2 additions & 14 deletions
16
app/list-objects/route.js → app/api/v1/s3/list-objects/route.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { S3Client } from "@aws-sdk/client-s3"; | ||
|
||
/** | ||
* S3 client. | ||
* | ||
* @type {S3Client} | ||
*/ | ||
const s3Client = new S3Client({ | ||
region: process.env.AWS_REGION, | ||
credentials: { | ||
accessKeyId: process.env.AWS_ACCESS_KEY_ID, | ||
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY, | ||
}, | ||
}); | ||
|
||
export default s3Client; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import slackWebApi from '../slack-web-api'; | ||
|
||
/** | ||
* Channel id for `#brand-performance-dashboard-notifications`. | ||
* | ||
* @type {String} | ||
*/ | ||
const SLACK_CHANNEL_ID = process.env.SLACK_CHANNEL_ID; | ||
|
||
export const dynamic = 'force-dynamic'; | ||
|
||
/** | ||
* Trigger the GitHub Workflow responsible for capturing screenshots with | ||
* Checkly. | ||
* | ||
* @param {Request} request Request object. | ||
*/ | ||
export async function POST(request) { | ||
try { | ||
const prefix = request.nextUrl.searchParams.get('prefix'); | ||
const link = `https://pmc-wayback-machine.vercel.app/#${prefix}`; | ||
const message = `<${link}|New Screenshots!>`; | ||
|
||
const success = await slackWebApi.chat.postMessage({ | ||
channel: SLACK_CHANNEL_ID, | ||
text: message, | ||
}); | ||
|
||
return Response.json({ success }); | ||
} catch(error) { | ||
return Response.json( | ||
{ error: 'Something went wrong! Check the logs.' }, | ||
{ status: 403 } | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { WebClient } from '@slack/web-api'; | ||
|
||
const web = new WebClient(process.env.SLACK_TOKEN ?? ''); | ||
|
||
export default web; |
Oops, something went wrong.