Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
hhdst committed Sep 30, 2024
0 parents commit 81175e6
Show file tree
Hide file tree
Showing 135 changed files with 41,498 additions and 0 deletions.
Empty file added .gitcreated
Empty file.
38 changes: 38 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts

/push.exe
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
This is a uservice project from Turing Research Team.
<img src="https://github.com/ArminKardan/utrialv2/blob/master/turing.png?raw=true"/>
## Getting Started

First, run the development server:

```bash
npm run dev -- -p 2000
# or
yarn dev -p 2000
```



Open [https://xtal.ir/userv](https://xtal.ir/userv) with your browser to see the result.

You can start editing the page by modifying `components/Pages/index.tsx`. The page auto-updates as you edit the file.
<br/>
<br/>

Binary file added Untitled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
137 changes: 137 additions & 0 deletions components/APIVerify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import { ObjectId } from "mongodb"
import { NextApiRequest, NextApiResponse } from "next"

import requestIp from 'request-ip'

export type APISession = {
uid: string,
name: string,
image: string,
imageprop: {
zoom: number,
x: number,
y: number,
portion: number,
refw: number
},
cchar: string,
unit: string,
workspace: string,
servid: ObjectId,
servsecret: string,
usedquota: number,
quota: number,
quotaunit: string,
status: "approved" | "rejected" | "waiting",
regdate: number,
expid: ObjectId,
role: string | null,
path: string,
devmod: boolean,
userip: string,
body: any
}

export default async (req: NextApiRequest, res: NextApiResponse): Promise<APISession> => {

if (global.Startup != "OK") {
if (global.Startup == "PENDING") {
await new Promise(r => setInterval(() => { if (global.Startup != "PENDING") r(null); else console.log("WAITING...") }, 100))
}
else {
global.Startup = "PENDING";
await (await import("../startup.ts")).Run()
global.Startup = "OK";
}
}

const userip = (requestIp.getClientIp(req)?.replace("::ffff:", "")) || "::"
var post = req.method?.toLowerCase() == "post"

if (post && !(req.body.startsWith("{") || req.body.startsWith("["))) {
return ({ userip }) as APISession
}
var body = post ? JSON.parse(req.body) : null;

if (post) {
if (body?.expid) {
body.expid = new global.ObjectId(body.expid)
}
if (body?.servid) {
body.servid = new global.ObjectId(body.servid)
}
if (body?.chatid) {
body.chatid = new global.ObjectId(body.chatid)
}
if (body?.msgid) {
body.msgid = new global.ObjectId(body.msgid)
}
if (body?.transid) {
body.transid = new global.ObjectId(body.transid)
}
if (body?.uid) {
body.uid = new global.ObjectId(body.uid)
}
}

if ((body?.passcode || body?.PASSCODE) && (body?.passcode || body?.PASSCODE) == process.env.PASSCODE) {
return {
name: "Service Bot",
role: "admin",
userip: "0.0.0.0",
uid: new global.ObjectId("635111afff61db2b04928f45"),
body,
} as APISession
}


let session = JSON.parse(`{}`)
let cookies = await import("cookies-next")

if (cookies.hasCookie("session", { req, res })) {
try {
session = cookies.getCookie("session", { req, res })
session = JSON.parse(decodeURIComponent(session))
} catch { }
}


let srv = {} as any
let user = null;
if (session.servid) {
srv = await api("http://localhost:3000/api/userv/servid", {
servid: session.servid,
servsecret: session.servsecret,
})


let u = global.db.collection("users")
let users = await u.find({}).project({ _id: 0 }).toArray()

for (let usr of users) {
if (MD5(usr.usersecret) == srv.usersecrethash) {
user = usr
}
}
}

if (session.servid) {
session.servid = new ObjectId(session.servid)
}
if (session.expid) {
session.expid = new ObjectId(session.expid)
}

console.log(session)


return {

...session,
...srv,
body,
role: user?.role || null,
nodeenv: global.nodeenv,
userip
} as APISession
}
5 changes: 5 additions & 0 deletions components/Libs/Bold.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default (props)=>{
return <span style={{fontFamily:lang.ffb || lang.ffb,
fontWeight:!lang.ffb?600:"normal",
...props.style}} onClick={()=>{props.on?.()}}>{props.children}</span>
}
1 change: 1 addition & 0 deletions components/Libs/Cap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default (txt:string):string=> txt.charAt(0).toUpperCase() + txt.slice(1);
23 changes: 23 additions & 0 deletions components/Libs/Checkbox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { CSSProperties } from "react";

export default (props:{on:(cheched:boolean)=>{}, style?:CSSProperties,
defaultChecked?:boolean, defaultValue?:boolean})=>
{
let uid = Math.floor(Math.random()*1000);
return <div className={styles.checkbox} style={props.style}>
<input className={styles.inpcbx} defaultChecked={props.defaultChecked || props.defaultValue}
id={`chk-${uid}`} type="checkbox" onChange={(e)=>{
props.on?.(e.target.checked)
}} autoComplete="off"/>
<label className={styles.cbx} htmlFor={`chk-${uid}`}><span>
<svg width="12px" height="10px">
<use href={`#check-${uid}`}></use>
</svg></span></label>

<svg className={styles.inlinesvg}>
<symbol id={`check-${uid}`} className="0 0 12 10">
<polyline points="1.5 6 4.5 9 10.5 1"></polyline>
</symbol>
</svg>
</div>
}
31 changes: 31 additions & 0 deletions components/Libs/Circle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

export default (props)=>{
function getProgressCircleValues(percentage, radius = 45) {
if (percentage < 0 || percentage > 100) {
throw new Error('Percentage must be between 0 and 100');
}

// Calculate the circumference of the circle
const circumference = 2 * Math.PI * radius;

// Calculate stroke-dasharray and stroke-dashoffset
const strokeDasharray = circumference;
const strokeDashoffset = circumference - (percentage / 100 * circumference);

return {
strokeDasharray: strokeDasharray.toFixed(2),
strokeDashoffset: strokeDashoffset.toFixed(2)
};
}

let v = getProgressCircleValues(props.percent)

return <svg width={props.width} height={props.width} viewBox="0 0 100 100">
<circle cx="50" cy="50" r="45" stroke="#e6e6e6" stroke-width="10" fill="none"/>

<circle cx="50" cy="50" r="45" stroke="#105609" stroke-width="10" fill="none"
stroke-dasharray={v.strokeDasharray} stroke-dashoffset={v.strokeDashoffset} transform="rotate(-90 50 50)"/>
<text x="50" y="50" font-size="20" text-anchor="middle" fill="#105609" dy=".3em">{props.percent+"%"}</text>
</svg>

}
21 changes: 21 additions & 0 deletions components/Libs/Comment.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

import Bold from './Bold'

export default (props: {
image: string, on?: () => void,
s?: number, title: string, comment: string
}) => {
return <div className={styles.cmlib} onClick={() => props.on?.()}>
<f-x >
<sp-2 />
<img src={global.cdn(props.image)} style={{ height: props.s || 50, width: props.s || 50, borderRadius: 17 }} /><sp-3 />
<c-xc>
<f-c>
<p style={{ paddingRight: 10 }}>
<Bold>{props.title}</Bold> <sp-4 />
{props.comment}</p>
</f-c>
</c-xc>
</f-x>
</div>
}
35 changes: 35 additions & 0 deletions components/Libs/Component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { useState } from 'react'

export type PageEl = (props: { [key in any]: any }, state: { [key in any]: any }, refresh: (object?: { [key in any]: any }) => void, getProps: (callback: () => Promise<void>) => void) => JSX.Element

const convertor = (props: any, Page: PageEl) => {
let [state, setState] = useState({ loaded: false, })
let [r, setR] = useState(0)
const setst = (obj) => {

if (obj) {
Object.keys(obj).forEach(k => {
state[k] = obj[k]
})
}
state["kdt"] = new Date().getTime()
setState(state)
setR(new Date().getTime())
// setState({ ...state, ...obj })
}
return Page(props, state, setst, async (func) => {
if (!state.loaded) {
await func();
state["loaded"] = true
state["kdt"] = new Date().getTime()
setState(state)
setR(new Date().getTime())
// setState({ ...state, loaded: true })
}
})
}


export default (props: any, Page: PageEl) => {
return convertor(props, Page)
}
23 changes: 23 additions & 0 deletions components/Libs/Copy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export default (textToCopy: string)=> {
// navigator clipboard api needs a secure context (https)
if (navigator.clipboard && window.isSecureContext) {
// navigator clipboard api method'
return navigator.clipboard.writeText(textToCopy);
} else {
// text area method
let textArea = document.createElement("textarea");
textArea.value = textToCopy;
// make the textarea out of viewport
textArea.style.position = "fixed";
textArea.style.left = "-999999px";
textArea.style.top = "-999999px";
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
return new Promise((res, rej) => {
// here the magic happens
document.execCommand('copy') ? res(null) : rej();
textArea.remove();
});
}
}
Loading

0 comments on commit 81175e6

Please sign in to comment.