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

Feature/api integration #109

Merged
merged 30 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5afe290
Added redirect to / without login 🔓
chirag3003 Jun 24, 2023
7a69008
↗ added redirect on deletion of logged in api key
chirag3003 Jun 24, 2023
880e816
⚙ fixed utils tab
chirag3003 Jun 24, 2023
4527b56
🗓 added last used in api key list
chirag3003 Jun 24, 2023
cfbf08e
🔥 fixed toast not appearing
chirag3003 Jun 24, 2023
523d394
fixed toaster
chirag3003 Jun 24, 2023
628c009
added markdown to dashboard homepage
chirag3003 Jun 24, 2023
3438b6b
removed unused readme file
chirag3003 Jun 24, 2023
4567df6
removed errors and warnings
chirag3003 Jun 24, 2023
16c648b
moved markdown converter to the mardown component
chirag3003 Jun 24, 2023
3b7c9f1
Merge branch 'dev' of github.com:BRAVO68WEB/shx into feature/api-inte…
chirag3003 Jun 24, 2023
669d65c
added error page for dashboard
chirag3003 Jun 24, 2023
5f5aef0
⚙ added error page for dashboard
chirag3003 Jun 24, 2023
949e8f8
⚙ updated api sdk
chirag3003 Jun 24, 2023
e37201f
added redirect in notes list
chirag3003 Jun 24, 2023
13aa51d
added note page and passkey validation
chirag3003 Jun 24, 2023
13d3679
✍ added copy button for notes link
chirag3003 Jun 24, 2023
71b715d
fixed copy note link
chirag3003 Jun 24, 2023
4b29715
changed redirect note to a new tab
chirag3003 Jun 24, 2023
80f42b0
🚑 fixed note requires password when note is not private
chirag3003 Jun 24, 2023
6fd6bbd
removed edit note button
chirag3003 Jun 24, 2023
6bd26d9
removed instanceURL accept system
chirag3003 Jun 24, 2023
ca381a0
Merge branch 'dev' into feature/api-integration
BRAVO68WEB Jun 24, 2023
0e35b04
Merge branch 'dev' of github.com:BRAVO68WEB/shx into feature/api-inte…
chirag3003 Jun 24, 2023
36e9ab3
added download link
chirag3003 Jun 24, 2023
60af98a
removed instanceurl field in settings
chirag3003 Jun 24, 2023
881a4b0
added remove tag
chirag3003 Jun 24, 2023
3fe8be6
Merge branch 'feature/api-integration' of github.com:BRAVO68WEB/shx i…
chirag3003 Jun 24, 2023
f6f612e
integrated sys info api
chirag3003 Jun 24, 2023
d0ff7da
removed warnings
chirag3003 Jun 24, 2023
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
4 changes: 2 additions & 2 deletions packages/dashboard/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class ApiSdk {
if (typeof window === 'undefined') {
const { cookies } = await import('next/headers');
config.headers['x-shx-api-key'] = cookies().get('apiKey')?.value;
config.baseURL = cookies().get('instanceUrl')?.value;

} else {
config.headers['x-shx-api-key'] = Cookies.get().apiKey ?? '';
config.baseURL = Cookies.get('instanceUrl') ?? '';
}
config.baseURL = process.env.NEXT_PUBLIC_INSTANCE_URL

return config;
});
Expand Down
25 changes: 14 additions & 11 deletions packages/dashboard/api/notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,27 @@ export class Notes {
constructor(axios: Axios) {
this.axios = axios;
}
async getAllNotes(search?:string) {
const res = await this.axios.get('/gist',{params:{search}});
async getAllNotes(search?: string) {
const res = await this.axios.get('/gist', { params: { search } });
const data = res.data.data as INote[];
return data;
}
async getSingleNote(id: string, passkey = '') {
const res = await this.axios.get(`/gist/${id}`, {
params: passkey ? { passkey } : {},
});
const data = res.data.data as INote;
return data;
}
async uploadSingleNote(data: AddNoteType) {
console.log("uploading")
if(!data.passkey){
delete data.passkey
}
console.log('uploading');
if (!data.passkey) {
delete data.passkey;
}
const res = await this.axios.post('/gist', data);
return res.data.data as INote;
}
async deleteSingleNote({
noteID,
}: {
noteID: string;
}) {
async deleteSingleNote({ noteID }: { noteID: string }) {
const res = await this.axios.delete(`/gist/${noteID}`);
return res;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/dashboard/api/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ export class Settings {
const res = await this.axios.post('/settings', {key, value});
return res
}
async getInstanceInfo(){
const res = await this.axios.get('/info/sys');
delete res.data.data.cpuUsage
delete res.data.data.memoryUsage
return res.data.data as ISysSettings
}
}

export default Settings;
11 changes: 11 additions & 0 deletions packages/dashboard/app/(dashboard)/dashboard/error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"use client"

import React from 'react'

function ErrorPage() {
return (
<div>ErrorPage</div>
)
}

export default ErrorPage
15 changes: 11 additions & 4 deletions packages/dashboard/app/(dashboard)/dashboard/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
import { sidebarGroups } from '@/lib/sidebar';
import { cookies } from 'next/headers';
import Link from 'next/link';
import React from 'react';
import { redirect } from 'next/navigation';

interface DashboardLayoutProps {
children: React.ReactNode;
}

const Layout = ({ children }: DashboardLayoutProps) => {
const cookieList = cookies();
const apiKey = cookieList.has('apiKey');
const masterKey = cookieList.has('masterKey');
if (!apiKey || !masterKey) redirect('/');
return (
<div className="flex h-screen">
<div className="sidebar w-full max-w-xs h-screen bg-black flex flex-col overflow-x-hidden overflow-y-auto">
{sidebarGroups.map((sidebarGrp, index) => {
return (
<div key={index} className="menu-group p-4">
<p className="title text-lg text-primary mb-2">{sidebarGrp.name}</p>
<p className="title text-lg text-primary mb-2">
{sidebarGrp.name}
</p>
{sidebarGrp.items.map((item, index) => {
return (
<Link
key={index}
key={index}
href={item.href}
className="p-2.5 block text-sm hover:bg-gray-900 w-full rounded-md"
>
Expand All @@ -29,7 +36,7 @@ const Layout = ({ children }: DashboardLayoutProps) => {
);
})}
</div>
<main className='w-full h-full overflow-y-auto p-5'>{children}</main>
<main className="w-full h-full overflow-y-auto p-5">{children}</main>
</div>
);
};
Expand Down
9 changes: 7 additions & 2 deletions packages/dashboard/app/(dashboard)/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import Markdown from '@/components/Markdown';
import axios from 'axios';
import React from 'react';

const Dashboard = () => {
const Dashboard = async () => {
const { data } = await axios.get(
'https://raw.githubusercontent.com/BRAVO68WEB/shx/dev/README.md'
);
return (
<>
<h1 className="text-5xl">Dasbhboard</h1>
<Markdown markdown={data} />
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,94 @@
'use client';

import Button from '@/components/ui/Button';
import axios from 'axios';
import Cookies from 'js-cookie';
import { Download } from 'lucide-react';
import React from 'react';
import React, { useEffect, useState } from 'react';
import { toast } from 'react-hot-toast';

const configs = [
{
name: 'Lorem Ipsum Config',
name: 'Image Config',
filename: 'image.sxcu',
url: `${process.env.NEXT_PUBLIC_INSTANCE_URL}/config/image.sxcu?apikey=`,
id: '1',
},
{
name: 'Lorem Cnofig',
id: '12',
name: 'Gist Config',
filename: 'gist.sxcu',
url: `${process.env.NEXT_PUBLIC_INSTANCE_URL}/config/gist.sxcu?apikey=`,
id: '2',
},
{
name: 'Lorem Config Config',
id: '13',
name: 'URL Config',
filename: 'url.sxcu',
url: `${process.env.NEXT_PUBLIC_INSTANCE_URL}/config/url.sxcu?apikey=`,
id: '3',
},
{
name: 'Lorem ',
id: '14',
name: 'File Config',
filename: 'file.sxcu',
url: `${process.env.NEXT_PUBLIC_INSTANCE_URL}/config/file.sxcu?apikey=`,
id: '4',
},
];

const downloadFile = ({
data,
fileName,
fileType,
}: {
data: string;
fileName: string;
fileType: string;
}) => {
// Create a blob with the data we want to download as a file
const blob = new Blob([data], { type: fileType });
// Create an anchor element and dispatch a click event on it
// to trigger a download
const a = document.createElement('a');
a.download = fileName;
a.href = window.URL.createObjectURL(blob);
const clickEvt = new MouseEvent('click', {
view: window,
bubbles: true,
cancelable: true,
});
a.dispatchEvent(clickEvt);
a.remove();
};
function Page() {
const [apiKey, setApiKey] = useState('');
useEffect(() => {
Fixed Show fixed Hide fixed
setApiKey(Cookies.get('apiKey') ?? '');
},[]);

async function onDownloadFile(url: string, filename: string) {
try {
const { data } = await axios.get(url);
console.log(data);
downloadFile({
data: JSON.stringify(data),
fileName: filename,
fileType: 'text/json',
});
} catch {
toast.error('Error downloading file');
}
}
return (
<>
{configs.map(({ name, id }) => {
{configs.map(({ name, id, url, filename }) => {
return (
<div
key={id}
className="w-full my-3 p-4 flex items-center justify-between bg-gray-900 rounded"
>
<p>{name}</p>
<Button size={'icon'} variant={'transparent'}>
<Button
size={'icon'}
onClick={() => onDownloadFile(`${url}${apiKey}`, filename)}
>
<Download />
</Button>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import api from '@/api';
import React from 'react';

function Page() {
const urls = [
{
id: 'afdas',
originalURL: 'https://www.google.com',
shortenedURL: 'https://www.google.com',
},
];
async function Page() {
const res = await api.settings.getInstanceInfo();
const data = Object.entries(res);

return (
<div>
Expand All @@ -29,19 +25,13 @@ function Page() {
</tr>
</thead>
<tbody className="divide-y p-2">
{urls.map(({ originalURL, shortenedURL, id }) => (
{data.map((val, id) => (
<tr className="bg-gray-900 rounded" key={id}>
<td className="whitespace-nowrap py-5 pl-4 pr-20 text-sm font-medium text-white">
<div className="flex items-center gap-3">
{originalURL}

</div>
<div className="flex items-center gap-3">{val[0]}</div>
</td>
<td className="whitespace-nowrap pl-4 text-sm font-medium text-white">
<div className="flex items-center gap-3">
{shortenedURL}

</div>
<div className="flex items-center gap-3">{val[1]}</div>
</td>
</tr>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import React, { ChangeEventHandler, useEffect, useState } from 'react';
import Button from '@/components/ui/Button';
import Input from '@/components/ui/Input';
import TagInput from '@/components/TagInput';
import api from '@/api';
import { toast } from 'react-hot-toast';
Expand Down Expand Up @@ -112,21 +111,16 @@ function Page() {
Save
</Button>
</div>
<div className="flex items-center w-full gap-4">
<Input
id="instance-url"
withLabel
label="Instance URL"
type="text"
className="w-full"
/>
<Button className="w-20 h-min ">Save</Button>
</div>
<div className="flex gap-4">
<TagInput
tags={settings.imageExtensions}
onAddTags={addImageExt}
placeholder="Image Extensions"
onChange={value =>
setSettings(old => {
return { ...old, imageExtensions: value };
})
}
/>

<Button
Expand All @@ -143,6 +137,11 @@ function Page() {
tags={settings.fileExtensions}
onAddTags={addFileExt}
placeholder="File Extensions"
onChange={value =>
setSettings(old => {
return { ...old, fileExtensions: value };
})
}
/>
<Button
onClick={() =>
Expand Down
32 changes: 22 additions & 10 deletions packages/dashboard/app/globals.css
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

*{
margin:0;
padding:0;
box-sizing: border-box;
:root {
--primary: #3a86ff;
--secondary: #8338ec;
}

:root{
--primary:#3A86FF;
--secondary:#8338EC;
body {
color: white;
}

body{
color:white
.markdown-body p:nth-child(3) {
display: flex;
gap: 10px;
}
.markdown-body p:nth-child(4) {
display: flex;
gap: 10px;
}
.markdown-body p:nth-child(5) {
display: flex;
gap: 10px;
}

@tailwind base;
@tailwind components;
@tailwind utilities;
@tailwind utilities;
Loading
Loading