mirror of https://gitee.com/godoos/godoos.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 lines
9.1 KiB
1 lines
9.1 KiB
import{b2 as S,b3 as d,b4 as R,b5 as W,b6 as $,aq as b,b7 as P,b8 as v}from"./index-4533c179.js";import{a as A,j as p,e as h,m,w as k}from"./files-57fe4531.js";function f(e,t){let n={},s=null,a=null;function o(){const i=[],r=[];for(const c in n)n.hasOwnProperty(c)&&(i.push(`${c} = $${r.length+1}`),r.push(n[c]));return{clause:i.length>0?`WHERE ${i.join(" AND ")}`:"",values:r}}const l={where:i=>(n={...n,...i},l),count:async()=>{var w;const{clause:i,values:r}=o(),u=`SELECT COUNT(*) as count FROM ${t} ${i}`;return((w=(await e.select(u,r))[0])==null?void 0:w.count)||0},page:(i,r)=>{const u=r,c=(i-1)*r;return s=u,a=c,l},select:async()=>{const{clause:i,values:r}=o();let u="";s!==null&&a!==null&&(u=`LIMIT ${s} OFFSET ${a}`);const c=`SELECT * FROM ${t} ${i} ${u}`;return await e.select(c,r)},find:async()=>{const{clause:i,values:r}=o(),u=`SELECT * FROM ${t} ${i} LIMIT 1`,c=await e.select(u,r);return c.length>0?c[0]:null}};return l}function T(e){const t=[],n=[];for(const a in e)e.hasOwnProperty(a)&&(t.push(`${a} = $${n.length+1}`),n.push(e[a]));return{clause:t.length>0?`WHERE ${t.join(" AND ")}`:"",values:n}}async function _(e,t,n,s){const a=new Date().toISOString(),o={...n,updated_at:a},l=Object.keys(o).map((w,x)=>`${w} = $${x+1}`).join(", "),i=Object.values(o),{clause:r,values:u}=T(s),c=`UPDATE ${t} SET ${l} ${r}`;await e.execute(c,[...i,...u])}function N(e){const t=S();if(!t)throw new Error("Database not initialized");return{create:async s=>{const a=new Date().toISOString(),o={...s,created_at:a,updated_at:a},l=Object.keys(o).join(", "),i=Object.keys(o).map((c,w)=>`$${w+1}`).join(", "),r=Object.values(o),u=`INSERT INTO ${e} (${l}) VALUES (${i})`;await t.execute(u,r)},update:async(s,a)=>{const o=new Date().toISOString(),l={...a,updated_at:o},i=Object.keys(l).map((c,w)=>`${c} = $${w+1}`).join(", "),r=Object.values(l),u=`UPDATE ${e} SET ${i} WHERE id = $${r.length+1}`;r.push(s),await t.execute(u,r)},save:s=>{const a=f(t,e),o=a.where;return a.where=l=>{const i=o(l);return i.select=async()=>(await _(t,e,s,l),[]),i},a},select:()=>f(t,e).select(),find:async()=>f(t,e).find(),findById:async s=>{const a=`SELECT * FROM ${e} WHERE id = $1`,o=await t.select(a,[s]);return o.length>0?o[0]:null},delete:async s=>{const a=`DELETE FROM ${e} WHERE id = $1`;await t.execute(a,[s])},where:s=>(console.log("where",s),f(t,e).where(s)),count:()=>f(t,e).count(),page:(s,a)=>f(t,e).page(s,a)}}const D=N("users");function C(e,t){return{code:0,success:!0,message:e,data:t,time:Math.floor(Date.now()/1e3)}}function E(e){return{code:-1,success:!1,message:e,time:Math.floor(Date.now()/1e3)}}var O;(function(e){e.WINDOW_RESIZED="tauri://resize",e.WINDOW_MOVED="tauri://move",e.WINDOW_CLOSE_REQUESTED="tauri://close-requested",e.WINDOW_DESTROYED="tauri://destroyed",e.WINDOW_FOCUS="tauri://focus",e.WINDOW_BLUR="tauri://blur",e.WINDOW_SCALE_FACTOR_CHANGED="tauri://scale-change",e.WINDOW_THEME_CHANGED="tauri://theme-changed",e.WINDOW_CREATED="tauri://window-created",e.WEBVIEW_CREATED="tauri://webview-created",e.DRAG_ENTER="tauri://drag-enter",e.DRAG_OVER="tauri://drag-over",e.DRAG_DROP="tauri://drag-drop",e.DRAG_LEAVE="tauri://drag-leave"})(O||(O={}));async function L(e,t){await d("plugin:event|unlisten",{event:e,eventId:t})}async function I(e,t,n){var s;const a=typeof(n==null?void 0:n.target)=="string"?{kind:"AnyLabel",label:n.target}:(s=n==null?void 0:n.target)!==null&&s!==void 0?s:{kind:"Any"};return d("plugin:event|listen",{event:e,target:a,handler:R(t)}).then(o=>async()=>L(e,o))}class y extends W{constructor(t){super(t)}static async load(t,n){const s=await d("plugin:store|load",{path:t,...n});return new y(s)}static async get(t){return await d("plugin:store|get_store",{path:t}).then(n=>n?new y(n):null)}async set(t,n){await d("plugin:store|set",{rid:this.rid,key:t,value:n})}async get(t){const[n,s]=await d("plugin:store|get",{rid:this.rid,key:t});return s?n:void 0}async has(t){return await d("plugin:store|has",{rid:this.rid,key:t})}async delete(t){return await d("plugin:store|delete",{rid:this.rid,key:t})}async clear(){await d("plugin:store|clear",{rid:this.rid})}async reset(){await d("plugin:store|reset",{rid:this.rid})}async keys(){return await d("plugin:store|keys",{rid:this.rid})}async values(){return await d("plugin:store|values",{rid:this.rid})}async entries(){return await d("plugin:store|entries",{rid:this.rid})}async length(){return await d("plugin:store|length",{rid:this.rid})}async reload(){await d("plugin:store|reload",{rid:this.rid})}async save(){await d("plugin:store|save",{rid:this.rid})}async onKeyChange(t,n){return await I("store://change",s=>{s.payload.resourceId===this.rid&&s.payload.key===t&&n(s.payload.exists?s.payload.value:void 0)})}async onChange(t){return await I("store://change",n=>{n.payload.resourceId===this.rid&&t(n.payload.key,n.payload.exists?n.payload.value:void 0)})}}let g;async function U(){return g||(g=await y.load("store.bin")),g}const j=1e3*60*60*24;async function F(e,t,n){const s=await U(),a=Date.now()+(n??j);await s.set(e,{value:t,expireAt:a}),await s.save()}function q(e,t,n={}){const{expiresIn:s="24h",refreshExpiresIn:a="7d"}=n,o=Math.floor(Date.now()/1e3);e.exp=o+M(s),e.refreshExp=o+M(a);const i=btoa(JSON.stringify({alg:"HS256",typ:"JWT"})),r=btoa(JSON.stringify(e)),u=$.md5(`${i}.${r}${t}`);return`${i}.${r}.${u}`}function M(e){const t=/^(\d+)([smhdw])$/,n=e.match(t);if(!n)throw new Error("Invalid expiresIn format");const s=parseInt(n[1],10);switch(n[2]){case"s":return s;case"m":return s*60;case"h":return s*3600;case"d":return s*86400;case"w":return s*604800;default:throw new Error("Unknown time unit")}}function B(){const e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let t="";for(let n=0;n<16;n++){const s=Math.floor(Math.random()*e.length);t+=e.charAt(s)}return t}const H=[{name:"computer",icon:"diannao",position:"Desktop,Menulist"},{name:"appstore",icon:"store",position:"Desktop,Menulist"},{name:"localchat",icon:"chat",position:"Desktop"},{name:"document",icon:"word",position:"Desktop"},{name:"excel",icon:"excel",position:"Desktop"},{name:"markdown",icon:"markdown",position:"Desktop"},{name:"mindmap",icon:"mindexe",position:"Desktop"},{name:"ppt",icon:"pptexe",position:"Desktop"},{name:"fileEditor",icon:"editorbt",position:"Desktop"},{name:"board",icon:"kanban",position:"Desktop"},{name:"whiteBoard",icon:"baiban",position:"Desktop"},{name:"piceditor",icon:"picedit",position:"Desktop"},{name:"gantt",icon:"gant",position:"Desktop"},{name:"browser",icon:"brower",position:"Desktop,Menulist"},{name:"setting",icon:"setting",position:"Menulist"},{name:"system.version",icon:"info",position:"Menulist"},{name:"process.title",icon:"progress",position:"Menulist"},{name:"calculator",icon:"calculator",position:"Menulist"},{name:"calendar",icon:"calendar",position:"Menulist"},{name:"musicStore",icon:"music",position:"Menulist"},{name:"gallery",icon:"gallery",position:"Menulist"},{name:"aiHelper",icon:"aiassistant",position:"Desktop"},{name:"aiModule",icon:"aidown",position:"Desktop"},{name:"aiSetting",icon:"aisetting",position:"Menulist"}],V=["Desktop","Menulist","Documents","Downloads","Music","Pictures","Videos","Schedule","Reciv"],G=["Word","Markdown","PPT","Baiban","Kanban","Excel","Mind","Screenshot","ScreenRecording"];async function J(){try{const e=await A(),t=await p(e,"C");await h(t)||await m(t,{recursive:!0});const n=["D","E","B"];for(const o of n){const l=await p(e,o);await h(l)||await m(l,{recursive:!0})}const s=await p(t,"System");await h(s)||await m(s,{recursive:!0});const a=await p(t,"Users");if(!await h(a)){await m(a,{recursive:!0});for(const u of V){const c=await p(a,u);await h(c)||await m(c,{recursive:!0})}const o=await p(a,"Documents");for(const u of G){const c=await p(o,u);await h(c)||await m(c,{recursive:!0})}const l=Q(),i=await p(a,"Desktop");for(const u of l.Desktop){const c=await p(i,u.Name);await h(c)||await k(c,new TextEncoder().encode(u.Content))}const r=await p(a,"Menulist");for(const u of l.Menulist){const c=await p(r,u.Name);await h(c)||await k(c,new TextEncoder().encode(u.Content))}}}catch(e){throw new Error(`InitOsSystem error: ${e}`)}}function Q(){const e=new Date;let t=1;const n=[],s=[];for(const a of H){const o=a.position.split(","),l=`link::Desktop::${a.name}::${a.icon}`;for(const i of o){const r={Name:`${a.name}.exe`,OldPath:`/C/Users/${i}/${a.name}.exe`,ParentPath:`/C/Users/${i}`,Content:l,Ext:"exe",Title:a.name,ID:t++,IsFile:!0,IsDir:!1,IsSymlink:!1,Size:l.length,ModTime:e,AccessTime:e,CreateTime:e,Mode:511};i==="Desktop"?n.push({...r,Path:`/C/Users/Desktop/${a.name}.exe`}):i==="Menulist"&&s.push({...r,Path:`/C/Users/Menulist/${a.name}.exe`})}}return{UpdateTime:e,Desktop:n,Menulist:s}}async function Y(e){const t=b(e.param),n=await D.where({username:t.username}).find();if(!n)return E("用户不存在,请注册用户!");if($.md5(t.password)!==n.password)return E("密码错误");const s=B(),a=q({id:n.id},s,{expiresIn:"24h"});return P(a),v(n.username),F("userid:"+n.id,s),await J(),C("登录成功",{user:n})}async function Z(){}async function X(e){return await D.where({username:e.username}).find()?E("用户已存在"):(e.password=$.md5(e.password),await D.create(e),C("注册成功",e))}async function ee(){return!1}async function te(){return[]}export{te as getThirdpartyList,ee as isLogin,Y as loginIn,Z as logout,X as register};
|
|
|