Get more done on packageserver

This commit is contained in:
2025-07-12 03:33:37 -05:00
parent 3ccb517aed
commit 35960d5db0
15 changed files with 441 additions and 78 deletions

View File

@@ -67,7 +67,18 @@ func Tesses.CrossLang.BuildTool(pm)
var objDir = "obj"; var objDir = "obj";
var srcDir = "src"; var srcDir = "src";
var resDir = "res"; var resDir = "res";
var compTime = "none";
var icon = ""; var icon = "";
if(TypeOf(configData.compTime) != "Undefined")
compTime = configData.compTime;
if(compTime == "full" && !this.AllowFullCompTime)
throw {
Type="CompTimeException",
Message="Failed to build due to having insecure comptime, use --allow-insecure-comptime if using the shell when building if you trust the program.",
ToString=(this)=>$"{this.Type} on line: {this.Line} {this.Message}"
};
if(TypeOf(configData.name) != "Undefined") if(TypeOf(configData.name) != "Undefined")
name = configData.name; name = configData.name;
@@ -144,7 +155,7 @@ func Tesses.CrossLang.BuildTool(pm)
{ {
if(item.Path == dirStr) return item.Data; if(item.Path == dirStr) return item.Data;
} }
func walk_for_compiling(item,dir2) func walk_for_compiling(item,dir2)
{ {
@@ -205,6 +216,7 @@ func Tesses.CrossLang.BuildTool(pm)
walk_for_compiling(dep,dir / outputDir); walk_for_compiling(dep,dir / outputDir);
} }
func walk_for_source(sourceDir) func walk_for_source(sourceDir)
{ {
each(var file : FS.Local.EnumeratePaths(sourceDir)) each(var file : FS.Local.EnumeratePaths(sourceDir))
@@ -229,6 +241,53 @@ func Tesses.CrossLang.BuildTool(pm)
var output = $"{name}-{version}.crvm"; var output = $"{name}-{version}.crvm";
var outFile = FS.Local.OpenFile(dir / outputDir / output,"wb"); var outFile = FS.Local.OpenFile(dir / outputDir / output,"wb");
var compTimeEnv = null;
if(compTime != "none")
{
//dir / outputDir;
var dict = {};
compTimeEnv = VM.CreateEnvironment(dict);
switch(compTime)
{
case "secure_file":
compTimeEnv.RegisterConsole();
compTimeEnv.RegisterClass();
compTimeEnv.RegisterCrypto();
compTimeEnv.RegisterDictionary();
compTimeEnv.RegisterJson();
compTimeEnv.RegisterRoot();
compTimeEnv.RegisterIO(false);
dict.FS.Local = new SubdirFilesystem(FS.Local,dir);
break;
case "full":
compTimeEnv.RegisterEverything();
break;
default:
//secure
compTimeEnv.RegisterConsole();
compTimeEnv.RegisterClass();
compTimeEnv.RegisterCrypto();
compTimeEnv.RegisterDictionary();
compTimeEnv.RegisterJson();
compTimeEnv.RegisterRoot();
compTimeEnv.RegisterIO(false);
break;
}
compTimeEnv.LockRegister();
each(var dep : file_deps)
{
compTimeEnv.LoadFileWithDependencies(FS.Local,dir/outputDir/$"{dep.Name}-{dep.Version}.crvm");
}
}
var result = VM.Compile({ var result = VM.Compile({
Name = name, Name = name,
@@ -239,7 +298,8 @@ func Tesses.CrossLang.BuildTool(pm)
Tools = file_tools, Tools = file_tools,
ResourceFileSystem = new SubdirFilesystem(FS.Local, dir / resDir), ResourceFileSystem = new SubdirFilesystem(FS.Local, dir / resDir),
Dependencies = file_deps, Dependencies = file_deps,
Output = outFile Output = outFile,
CompTime = compTimeEnv
}); });
outFile.Close(); outFile.Close();

View File

@@ -49,6 +49,9 @@ func DB.LoginButton(ctx,active,$accountPage)
func DB.CanUploadPackagePrefix(userId, packageName) func DB.CanUploadPackagePrefix(userId, packageName)
{ {
var prefix = packageName.Split(".",true,2); var prefix = packageName.Split(".",true,2);
if(prefix.Length >= 1)
prefix = prefix[0];
else return false;
DB.Lock(); DB.Lock();
var dbCon = DB.Open(); var dbCon = DB.Open();
var exec = Sqlite.Exec(dbCon, $"SELECT * FROM reserved_prefixes WHERE prefix = {Sqlite.Escape(prefix)};"); var exec = Sqlite.Exec(dbCon, $"SELECT * FROM reserved_prefixes WHERE prefix = {Sqlite.Escape(prefix)};");
@@ -158,7 +161,7 @@ func DB.UpdateVersion(pkgInfo)
//CREATE TABLE IF NOT EXISTS versions (id INTEGER PRIMARY KEY AUTOINCREMENT, packageId INTEGER, version INTEGER, description TEXT, type TEXT, maintainer TEXT, homepage TEXT, repo TEXT, license TEXT); //CREATE TABLE IF NOT EXISTS versions (id INTEGER PRIMARY KEY AUTOINCREMENT, packageId INTEGER, version INTEGER, description TEXT, type TEXT, maintainer TEXT, homepage TEXT, repo TEXT, license TEXT);
//VALUES ({pkgId},{version},{Sqlite.Escape(description)},{Sqlite.Escape(type)},{Sqlite.Escape(maintainer)},{Sqlite.Escape(homepage)},{Sqlite.Escape(repo)},{Sqlite.Escape(license)}); //VALUES ({pkgId},{version},{Sqlite.Escape(description)},{Sqlite.Escape(type)},{Sqlite.Escape(maintainer)},{Sqlite.Escape(homepage)},{Sqlite.Escape(repo)},{Sqlite.Escape(license)});
Sqlite.Exec(dbCon,$"UPDATE versions SET description = {Sqlite.Escape(description)}, type = {Sqlite.Escape(type)}, maintainer = {Sqlite.Escape(maintainer)}, homepage = {Sqlite.Escape(homepage)}, repo = {Sqlite.Escape(repo)}, license = {Sqlite.Escape(license)}, uploadTime = {Time.Now} WHERE packageId = {pkgId} AND version = {version};"); Sqlite.Exec(dbCon,$"UPDATE versions SET description = {Sqlite.Escape(description)}, type = {Sqlite.Escape(type)}, maintainer = {Sqlite.Escape(maintainer)}, homepage = {Sqlite.Escape(homepage)}, repo = {Sqlite.Escape(repo)}, license = {Sqlite.Escape(license)}, uploadTime = {DateTime.NowEpoch} WHERE packageId = {pkgId} AND version = {version};");
Sqlite.Close(dbCon); Sqlite.Close(dbCon);
DB.Unlock(); DB.Unlock();
@@ -196,7 +199,7 @@ func DB.AddVersion(pkgInfo)
//CREATE TABLE IF NOT EXISTS versions (id INTEGER PRIMARY KEY AUTOINCREMENT, packageId INTEGER, version INTEGER, description TEXT, type TEXT, maintainer TEXT, homepage TEXT, repo TEXT, license TEXT); //CREATE TABLE IF NOT EXISTS versions (id INTEGER PRIMARY KEY AUTOINCREMENT, packageId INTEGER, version INTEGER, description TEXT, type TEXT, maintainer TEXT, homepage TEXT, repo TEXT, license TEXT);
Sqlite.Exec(dbCon,$"INSERT INTO versions (packageId,version,description,type,maintainer,homepage,repo,license,uploadTime) VALUES ({pkgId},{version},{Sqlite.Escape(description)},{Sqlite.Escape(type)},{Sqlite.Escape(maintainer)},{Sqlite.Escape(homepage)},{Sqlite.Escape(repo)},{Sqlite.Escape(license)},{Time.Now});"); Sqlite.Exec(dbCon,$"INSERT INTO versions (packageId,version,description,type,maintainer,homepage,repo,license,uploadTime) VALUES ({pkgId},{version},{Sqlite.Escape(description)},{Sqlite.Escape(type)},{Sqlite.Escape(maintainer)},{Sqlite.Escape(homepage)},{Sqlite.Escape(repo)},{Sqlite.Escape(license)},{DateTime.NowEpoch});");
Sqlite.Close(dbCon); Sqlite.Close(dbCon);
DB.Unlock(); DB.Unlock();
@@ -294,7 +297,19 @@ func DB.GetUserIdFromSession(session)
return -1; return -1;
} }
func DB.GetSessionFromBearer(ctx)
{
var auth = ctx.RequestHeaders.TryGetFirst("Authorization");
if(TypeOf(auth) == "String")
{
auth=auth.Split(" ",true,2);
if(auth.Length < 2) return null;
if(auth[0] != "Bearer") return null;
var uid = DB.GetUserIdFromSession(auth[1]);
if(uid != -1) return auth[1];
}
return null;
}
func DB.GetSession(ctx) func DB.GetSession(ctx)
{ {
var cookie = ctx.RequestHeaders.TryGetFirst("Cookie"); var cookie = ctx.RequestHeaders.TryGetFirst("Cookie");
@@ -337,7 +352,7 @@ func DB.CreateCSRF(ctx)
var csrf = Crypto.Base64Encode(Crypto.RandomBytes(32, "CPKG")); var csrf = Crypto.Base64Encode(Crypto.RandomBytes(32, "CPKG"));
var expires = Time.Now + 600; var expires = DateTime.NowEpoch + 600;
DB.Lock(); DB.Lock();
DB.csrf.Add({ DB.csrf.Add({
Token = csrf, Token = csrf,
@@ -358,7 +373,7 @@ func DB.VerifyCSRF(session,csrf)
if(csrf.Length == 0) return false; if(csrf.Length == 0) return false;
var retVal = false; var retVal = false;
var time = Time.Now; var time = DateTime.NowEpoch;
DB.Lock(); DB.Lock();
var _oldCSRF = DB.csrf; var _oldCSRF = DB.csrf;
DB.csrf = []; DB.csrf = [];
@@ -661,7 +676,6 @@ func DB.QueryPackages(q, offset, limit)
DB.Lock(); DB.Lock();
var dbCon = DB.Open(); var dbCon = DB.Open();
var res = Sqlite.Exec(dbCon, sql); var res = Sqlite.Exec(dbCon, sql);
Sqlite.Close(dbCon); Sqlite.Close(dbCon);
DB.Unlock(); DB.Unlock();

View File

@@ -1,11 +1,10 @@
func Components.Package(name,version,owner,upload,desc) func Components.Package(name,version,owner,upload,desc)
{ {
var image = $"./api/v1/package_icon.png?name={Net.Http.UrlEncode(name)}&version={Net.Http.UrlEncode(version)}"; var image = $"./api/v1/package_icon.png?name={Net.Http.UrlEncode(name)}&version={Net.Http.UrlEncode(version)}";
var pkgUrl = $"./package?name={Net.Http.UrlEncode(name)}"; var pkgUrl = $"./package?name={Net.Http.UrlEncode(name)}";
return <li> return <li>
<img width={"64"} height={"64"} src={image} alt={"icon"}> <img width={"64"} height={"64"} src={image} alt={"icon"}>
<a href={pkgUrl}>{name}</a> | <span>By: {owner}</span> <a href={pkgUrl}>{name}</a> | <span>By: <a href={$"./account?name={owner}"}>{owner}</a></span>
<br> <br>
<span>Updated: {upload} | Latest version: {version}</span> <span>Updated: {upload} | Latest version: {version}</span>
<p>{desc}</p> <p>{desc}</p>

View File

@@ -1,16 +1,24 @@
func Shell(title,pages,body) func Shell(title,pages,body)
{ {
var shell= var shell=
<html lang={"en"}> <html lang={"en"} data-bs-theme="dark">
<head> <head>
<meta charset={"UTF-8"}> <meta charset={"UTF-8"}>
<meta name={"viewport"} content={"width=device-width, initial-scale=1.0"}> <meta name={"viewport"} content={"width=device-width, initial-scale=1.0"}>
<link rel={"stylesheet"} href={"./css/bootstrap.min.css"}> <link rel={"stylesheet"} href={"./css/bootstrap.min.css"}>
<title>CPKG - {title}</title> <title>CPKG - {title}</title>
<noscript>
<style>
.navbar-toggler {"{"}
display:none;
}
</style>
</noscript>
</head> </head>
<body> <body>
<header> <header>
<nav class={"navbar navbar-expand-lg"} style={"background-color: #ffff00;"}> <nav class={"navbar navbar-expand-lg"} data-bs-theme="light" style={"background-color: orange;"}>
<div class={"container-fluid"}> <div class={"container-fluid"}>
<a class={"navbar-brand"} href={"./"}>CPKG</a> <a class={"navbar-brand"} href={"./"}>CPKG</a>
<button class={"navbar-toggler"} type={"button"} data-bs-toggle={"collapse"} data-bs-target={"#navbarNav"} aria-controls={"navbarNav"} aria-expanded={"false"} aria-label={"Toggle navigation"}> <button class={"navbar-toggler"} type={"button"} data-bs-toggle={"collapse"} data-bs-target={"#navbarNav"} aria-controls={"navbarNav"} aria-expanded={"false"} aria-label={"Toggle navigation"}>
@@ -33,7 +41,24 @@ func Shell(title,pages,body)
</ul> </ul>
</div> </div>
</div> </div>
<noscript>
<ul class={"d-none d-xs-block d-sm-block d-md-block d-lg-none navbar-nav"}>
<each(var item : pages)>
<li class={"nav-item"}>
<if(item.active)>
<true>
<a class={"nav-link active"} aria-current={"page"} href={item.route}>{item.text}</a>
</true>
<false>
<a class={"nav-link"} href={item.route}>{item.text}</a>
</false>
</if>
</li>
</each>
</ul>
</noscript>
</nav> </nav>
</header> </header>
<br> <br>

View File

@@ -81,8 +81,7 @@ func Pages.Account(ctx)
<if(TypeOf(user) == "Dictionary")> <if(TypeOf(user) == "Dictionary")>
<true> <true>
<h1>{user.accountName}</h1> <h1>{user.accountName}</h1>
<a href={$"./account_packages?name={Net.Http.UrlEncode(name)}"}>Packages</a> <a href={$"./account_packages?name={Net.Http.UrlEncode(name)}"}>Packages</a>|<a href={$"./reserved_prefixes?name={Net.Http.UrlEncode(name)}"}>Reserved Prefixes</a>
<if(active.active)> <if(active.active)>
<true> <true>

View File

@@ -22,6 +22,8 @@ func Pages.Index(ctx)
<input type={"search"} name={"q"} class={"form-control"} placeholder={"Search for packages..."} aria-label={"Search for packages..."} aria-describedby={"button-search"}> <input type={"search"} name={"q"} class={"form-control"} placeholder={"Search for packages..."} aria-label={"Search for packages..."} aria-describedby={"button-search"}>
<button class={"btn btn-outline-secondary"} type={"submit"} id={"button-search"}>Search</button> <button class={"btn btn-outline-secondary"} type={"submit"} id={"button-search"}>Search</button>
</div> </div>
<a href="./api">API</a>
</div> </div>
<div class={"col"}> <div class={"col"}>

View File

@@ -1,6 +1,7 @@
func Pages.Package(ctx,name) func Pages.Package(ctx,name)
{ {
var package = DB.GetPackageVersions(name); var package = DB.GetPackageVersions(name);
var pages = [ var pages = [
{ {
@@ -15,7 +16,34 @@ func Pages.Package(ctx,name)
}, },
DB.LoginButton(ctx,false) DB.LoginButton(ctx,false)
]; ];
var installCmd = "";
if(package.Length > 0)
{
switch(package[0].type)
{
case "lib":
case "compiler_tool":
installCmd = $"crosslang add-dependency {name}";
break;
case "console":
installCmd = $"crosslang install-console {name} --version={package[0].version}";
break;
case "app":
installCmd = $"crosslang install-app {name} --version={package[0].version}";
break;
case "tool":
installCmd = $"crosslang install-tool {name} --version={package[0].version}";
break;
case "template":
installCmd = $"crosslang install-template {name} --version={package[0].version}";
break;
default:
installCmd = "No instructions to install sorry.";
break;
}
}
var html = <if(package.Length > 0)><true><section class={"container"}> var html = <if(package.Length > 0)><true><section class={"container"}>
@@ -29,29 +57,33 @@ func Pages.Package(ctx,name)
<li class={"nav-item"} role={"presentation"}> <li class={"nav-item"} role={"presentation"}>
<button class={"nav-link active"} id={"home-tab"} data-bs-toggle={"tab"} data-bs-target={"#home-tab-pane"} type={"button"} role={"tab"} aria-controls={"home-tab-pane"} aria-selected={"true"}>CLI</button> <button class={"nav-link active"} id={"home-tab"} data-bs-toggle={"tab"} data-bs-target={"#home-tab-pane"} type={"button"} role={"tab"} aria-controls={"home-tab-pane"} aria-selected={"true"}>CLI</button>
</li> </li>
<if(package[0].type == "lib" || package[0].type == "compile_tool")>
<true>
<li class={"nav-item"} role={"presentation"}> <li class={"nav-item"} role={"presentation"}>
<button class={"nav-link"} id={"profile-tab"} data-bs-toggle={"tab"} data-bs-target={"#profile-tab-pane"} type={"button"} role={"tab"} aria-controls={"profile-tab-pane"} aria-selected={"false"}>cross.json</button> <button class={"nav-link"} id={"profile-tab"} data-bs-toggle={"tab"} data-bs-target={"#profile-tab-pane"} type={"button"} role={"tab"} aria-controls={"profile-tab-pane"} aria-selected={"false"}>cross.json</button>
</li> </li>
</true>
</if>
</ul> </ul>
<div class={"tab-content"} id={"myTabContent"}> <div class={"tab-content"} id={"myTabContent"}>
<div class={"tab-pane fade show active"} id={"home-tab-pane"} role={"tabpanel"} aria-labelledby={"home-tab"} tabindex={"0"}><div class={"card"}> <div class={"tab-pane fade show active"} id={"home-tab-pane"} role={"tabpanel"} aria-labelledby={"home-tab"} tabindex={"0"}><div class={"card"}>
<div class={"card-body"}> <div class={"card-body"}>
<if(package[0].type == "lib" || package[0].type == "compile_tool")> {installCmd}
<true>
crosslang add-dependency {name}
</true>
</if>
</div> </div>
</div> </div>
</div> </div>
<div class={"tab-pane fade"} id={"profile-tab-pane"} role={"tabpanel"} aria-labelledby={"profile-tab"} tabindex={"0"}><div class={"card"}> <if(package[0].type == "lib" || package[0].type == "compile_tool")>
<true>
<div class={"tab-pane fade"} id={"profile-tab-pane"} role={"tabpanel"} aria-labelledby={"profile-tab"} tabindex={"0"}><div class={"card"}>
<div class={"card-body"}> <div class={"card-body"}>
{Json.Encode({name=name,version = package[0].version })} {Json.Encode({name=name,version = package[0].version })}
</div> </div>
</div> </div>
</div> </div>
</true>
</if>
</div> </div>
<br> <br>
<h3>More options and info</h3> <h3>More options and info</h3>
@@ -77,7 +109,7 @@ func Pages.Package(ctx,name)
<li>Repo: <a href={package[0].repo}>{package[0].repo}</a></li> <li>Repo: <a href={package[0].repo}>{package[0].repo}</a></li>
</true> </true>
</if> </if>
<li>Last updated: {package[0].uploadDate}</li> <li>Last updated: {new DateTime(package[0].uploadTime).ToString("%Y/%m/%d %H:%M:%S UTC")}</li>
<li>Latest version: {package[0].version}</li> <li>Latest version: {package[0].version}</li>
<li>Type: {package[0].type}</li> <li>Type: {package[0].type}</li>
<li><a href={package[0].download}>Download</a></li> <li><a href={package[0].download}>Download</a></li>
@@ -118,7 +150,7 @@ func Pages.Package(ctx,name)
<li>Repo: <a href={package[i].repo}>{package[i].repo}</a></li> <li>Repo: <a href={package[i].repo}>{package[i].repo}</a></li>
</true> </true>
</if> </if>
<li>Uploaded: {package[i].uploadDate}</li> <li>Uploaded: {new DateTime(package[i].uploadTime).ToString("%Y/%m/%d %H:%M:%S UTC")}</li>
<li>Type: {package[i].type}</li> <li>Type: {package[i].type}</li>
<li><a href={package[i].download}>Download</a></li> <li><a href={package[i].download}>Download</a></li>
</ul> </ul>

View File

@@ -1,6 +1,8 @@
func Pages.Packages(ctx) func Pages.Packages(ctx)
{ {
var q = ctx.QueryParams.TryGetFirst("q"); var q = ctx.QueryParams.TryGetFirst("q");
var page = ParseLong(ctx.QueryParams.TryGetFirst("page"));
page = TypeOf(page) != "Long" ? 1 : page;
if(TypeOf(q) != "String") q = ""; if(TypeOf(q) != "String") q = "";
var pages = [ var pages = [
{ {
@@ -34,8 +36,8 @@ func Pages.Packages(ctx)
</article> </article>
+ +
<ul> <ul>
<each(var item : DB.QueryPackages(q,0,20))> <each(var item : DB.QueryPackages(q,(page-1)*20,20))>
<raw(Components.Package(item.packageName,item.version,item.accountName,item.uploadDate,item.description))> <raw(Components.Package(item.packageName,item.version,item.accountName,new DateTime(item.uploadTime).ToString("%Y/%m/%d"),item.description))>
</each> </each>
</ul>; </ul>;
return Shell("Packages",pages,html); return Shell("Packages",pages,html);

View File

@@ -1,18 +1,15 @@
var count = 0;
func main(args) func main(args)
{ {
Console.WriteLine("In main");
var dir = "."; var dir = ".";
if(args.Length > 1) if(args.Length > 1)
{ {
dir = args[1]; dir = args[1];
} }
DB.Init(dir); DB.Init(dir);
//should be a route but its crosslang so we can use mountable //should be a route but its crosslang so we can use mountable
mountable.Mount("/package_icon.png", (ctx)=>{ mountable.Mount("/package_icon.png", (ctx)=>{
ctx.ResponseHeaders.SetValue("Content-Type", "image/png"); ctx.ResponseHeaders.SetValue("Content-Type", "image/png");
@@ -22,7 +19,7 @@ func main(args)
/* /*
PUT /api/v1/upload Authorization Bearer PUT /api/v1/upload Authorization Bearer
POST /api/v1/login Json object with username and password returns json object with either 200 for success {"token": "TOKEN_VAL"} or non 2XX if fails {"reason": "SOME ERROR"} POST /api/v1/login Json object with email and password returns json object with either 200 for success {"token": "TOKEN_VAL"} or non 2XX if fails {"reason": "SOME ERROR"}
POST /api/v1/logout use Authorization Bearer POST /api/v1/logout use Authorization Bearer
GET /api/v1/latest?name=PackageName returns 200 OK with json {"version": "1.0.0.0-prod"} if it succeeds if it fails returns a failing status code with {"reason": "SOME ERROR"} GET /api/v1/latest?name=PackageName returns 200 OK with json {"version": "1.0.0.0-prod"} if it succeeds if it fails returns a failing status code with {"reason": "SOME ERROR"}
GET /api/v1/download?name=PackageName&version=1.0.0.0-prod returns 200 OK with package bytes or 404 if doesn't exist GET /api/v1/download?name=PackageName&version=1.0.0.0-prod returns 200 OK with package bytes or 404 if doesn't exist
@@ -149,7 +146,7 @@ func main(args)
var csrf = ctx.QueryParams.TryGetFirst("csrf"); var csrf = ctx.QueryParams.TryGetFirst("csrf");
var result = { Success=false, Reason = "Invalid CSRF"}; var result = { Success=false, Reason = "Invalid CSRF"};
if(DB.VerifyCSRF(session,csrf)) if(!DB.VerifyCSRF(session,csrf))
{ {
var userId = DB.GetUserIdFromSession(session); var userId = DB.GetUserIdFromSession(session);
result = DB.UploadPackage(userId, filePath); result = DB.UploadPackage(userId, filePath);
@@ -175,6 +172,100 @@ func main(args)
} }
} }
if(ctx.Path == "/api")
{
ctx.WithMimeType("text/html").SendText(Pages.API.Index());
return true;
}
if(ctx.Path == "/api-v1")
{
ctx.WithMimeType("text/html").SendText(Pages.API.V1());
return true;
}
if(ctx.Path == "/api/v1/upload")
{
if(ctx.Method == "PUT")
{
var session = DB.GetSessionFromBearer(ctx);
if(session == null)
{
ctx.StatusCode=401;
ctx.SendJson({
reason = "You are not logged in"
});
return true;
}
var userId = DB.GetUserIdFromSession(session);
var filePath = DB.working / "Temp" / $"{DB.GetUniqueNumber()}.crvm";
var strm = FS.Local.OpenFile(filePath,"wb");
ctx.ReadStream(strm);
strm.Close();
var result = DB.UploadPackage(userId, filePath);
if(result.Success)
{
ctx.StatusCode = 204;
ctx.ResponseHeaders.SetValue("Content-Length","0");
ctx.WriteHeaders();
return true;
}
else {
ctx.StatusCode = 400;
ctx.SendJson({reason = result.Reason});
return true;
}
}
else {
ctx.StatusCode = 400;
ctx.SendJson({
reason = $"Expected PUT method got {ctx.Method}"
});
}
return true;
}
if(ctx.Path == "/api/v1/login")
{
if(ctx.Method == "POST")
{
var json = ctx.ReadJson();
if(TypeOf(json) != "Dictionary" || TypeOf(json.email) != "String" || TypeOf(json.password) != "String") {
ctx.StatusCode = 400;
ctx.SendJson({
reason = "Expected a Json Dictionary, with the email and password"
});
return true;
}
var accountId = DB.GetAccountId(json.email, json.password);
if(accountId == -1)
{
ctx.StatusCode = 401;
ctx.SendJson({
reason = "Invalid credentials"
});
return true;
}
ctx.SendJson({
token = DB.CreateSession(accountId)
});
return true;
}
else {
ctx.StatusCode = 400;
ctx.SendJson({
reason = $"Expected POST method got {ctx.Method}"
});
}
return true;
}
if(ctx.Path == "/api/v1/package_icon.png") if(ctx.Path == "/api/v1/package_icon.png")
{ {
var name = ctx.QueryParams.TryGetFirst("name"); var name = ctx.QueryParams.TryGetFirst("name");

View File

@@ -15,6 +15,7 @@ func main(args)
else if(commandName == "build") else if(commandName == "build")
{ {
var offline=false; var offline=false;
var allowFullCompTime=false;
var buildPath = "."; var buildPath = ".";
if(dd.Arguments.Count > 1) if(dd.Arguments.Count > 1)
{ {
@@ -26,12 +27,17 @@ func main(args)
{ {
offline = true; offline = true;
} }
if(flag == "allow-insecure-comptime")
{
allowFullCompTime=true;
}
if(flag == "help") if(flag == "help")
{ {
Console.WriteLine("USAGE: crosslang build [build-flags-and-options]"); Console.WriteLine("USAGE: crosslang build [build-flags-and-options]");
Console.WriteLine("FLAGS:"); Console.WriteLine("FLAGS:");
Console.WriteLine("offline: build with no internet (don't fetch files)"); Console.WriteLine("offline: build with no internet (don't fetch files)");
Console.WriteLine("help: this help"); Console.WriteLine("help: this help");
Console.WriteLine("allow-insecure-comptime: Allow full comptime");
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("OPTIONS:"); Console.WriteLine("OPTIONS:");
Console.WriteLine("conf=CONFIGSTRING: specify a conf string for compile_tool(s), is the property Config"); Console.WriteLine("conf=CONFIGSTRING: specify a conf string for compile_tool(s), is the property Config");
@@ -50,6 +56,7 @@ func main(args)
pm.Offline = offline; pm.Offline = offline;
var bt = Tesses.CrossLang.BuildTool(pm); var bt = Tesses.CrossLang.BuildTool(pm);
bt.Config = conf; bt.Config = conf;
bt.AllowFullCompTime = allowFullCompTime;
bt.BuildProject(buildPath); bt.BuildProject(buildPath);
} }
else if(commandName == "run") else if(commandName == "run")
@@ -57,6 +64,7 @@ func main(args)
var offline=false; var offline=false;
var buildPath = "."; var buildPath = ".";
var nobuild=false; var nobuild=false;
var allowFullCompTime=false;
var output=""; var output="";
each(var flag : dd.Flags) each(var flag : dd.Flags)
{ {
@@ -64,14 +72,19 @@ func main(args)
{ {
offline = true; offline = true;
} }
else if(flag == "allow-insecure-comptime")
{
allowFullCompTime=true;
}
else if(flag == "help") else if(flag == "help")
{ {
Console.WriteLine("USAGE: crosslang run [run-flags-and-options] program-arguments..."); Console.WriteLine("USAGE: crosslang run [run-flags-and-options] program-arguments...");
Console.WriteLine("USAGE: crosslang run [run-flags-and-options] -- program-arguments-and-options..."); Console.WriteLine("USAGE: crosslang run [run-flags-and-options] -- program-arguments-and-options...");
Console.WriteLine("FLAGS:"); Console.WriteLine("FLAGS:");
Console.WriteLine("offline: build with no internet (don't fetch files)"); Console.WriteLine("offline: build with no internet (don't fetch files)");
Console.WriteLine("help: this help"); Console.WriteLine("allow-insecure-comptime: Allow full comptime");
Console.WriteLine("nobuild: don't build, just run"); Console.WriteLine("nobuild: don't build, just run");
Console.WriteLine("help: this help");
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("OPTIONS:"); Console.WriteLine("OPTIONS:");
Console.WriteLine("conf=CONFIGSTRING: specify a conf string for compile_tool(s), is the property Config"); Console.WriteLine("conf=CONFIGSTRING: specify a conf string for compile_tool(s), is the property Config");
@@ -116,6 +129,7 @@ func main(args)
pm.Offline = offline; pm.Offline = offline;
var bt = Tesses.CrossLang.BuildTool(pm); var bt = Tesses.CrossLang.BuildTool(pm);
bt.Config = conf; bt.Config = conf;
bt.AllowFullCompTime = allowFullCompTime;
output = bt.BuildProject(buildPath).Output; output = bt.BuildProject(buildPath).Output;
} }
var env = VM.CreateEnvironment({}); var env = VM.CreateEnvironment({});
@@ -465,7 +479,7 @@ func main(args)
} }
else if(commandName == "install-console") else if(commandName == "install-console")
{ {
//crosslang install-console //crosslang install-console ConsoleApp --version=1.0.0.0-prod [--outdir=DIR]
} }
else if(commandName == "install-app") else if(commandName == "install-app")
{ {
@@ -606,6 +620,10 @@ func main(args)
{ {
//crosslang console myfavoriteapp //crosslang console myfavoriteapp
} }
else if(commandName == "app")
{
Tesses.CrossLang.Shell.App(dd);
}
else if(commandName == "tool") else if(commandName == "tool")
{ {
@@ -750,13 +768,141 @@ func main(args)
} }
else if(commandName == "upload-package") else if(commandName == "upload-package")
{ {
//crosslang upload-package [PACKAGE_NAME] //crosslang upload-package [--host=HOST --token=TOKEN] [--session=NAME] [PACKAGE_FILE]
var host=null;
var token=null;
var session=null;
var package=null;
var nobuild=false;
each(var option : dd.Options)
{
if(option.Key == "host")
{
host = option.Value;
}
if(option.Key == "token")
{
token = option.Value;
}
if(option.Key == "session")
{
session = option.Value;
}
}
if(dd.Arguments.Length > 1)
{
package = dd.Arguments[1];
}
else {
if(nobuild)
{
throw {Type="NotImplementedException", Message="nobuild on upload-package is not implemented",ToString=(this)=>$"{this.Type} on line: {this.Line}: {this.Message}"};
}
else {
var pm = Tesses.CrossLang.PackageManager();
pm.Offline = false;
var bt = Tesses.CrossLang.BuildTool(pm);
bt.Config = "";
bt.AllowFullCompTime = false;
package = bt.BuildProject(".").Output;
}
}
if(TypeOf(host) != "String" || TypeOf(token) != "String")
{
if(FS.Local.FileExists(Env.CrossLangConfig / "auth.json"))
{
var json = Json.Decode(FS.ReadAllText(FS.Local,Env.CrossLangConfig / "auth.json"));
if(json.Length == 0)
{
Console.WriteLine("The auth.json file is empty, use crosslang login to login");
return 1;
}
else if(json.Length == 1)
{
host = json[0].host;
token = json[0].token;
}
else {
if(TypeOf(session) != "String")
{
Console.WriteLine("Multiple entries in auth.json file, session is ambiguous.");
Console.WriteLine("Sessions:");
each(var item : json)
{
Console.WriteLine($"{item.name}: {item.host}");
}
return 1;
}
else {
var found=false;
each(var item : json)
{
if(item.name == session)
{
found=true;
host = item.host;
token = item.token;
break;
}
}
if(!found) {
Console.WriteLine($"Could not find session with name: {session}");
return 1;
}
}
}
}
else { Console.WriteLine("No auth.json file, use crosslang login to login"); return 1;}
}
if(TypeOf(host) != "String" || TypeOf(token) != "String")
{
Console.WriteLine("You are not logged in, use crosslang login to login");
return 1;
}
var strm = FS.Local.OpenFile(package,"rb");
if(strm == null)
{
Console.WriteLine("Could not open file");
return 1;
}
var req = {
Method="PUT",
RequestHeaders = [
{Key= "Authorization",Value=$"Bearer {token}"}
],
Body = Net.Http.StreamHttpRequestBody(strm,"application/crvm")
};
var http = Net.Http.MakeRequest($"{host.TrimEnd('/')}/api/v1/upload",req);
if(http.StatusCode == 204)
{
Console.WriteLine("Uploaded package successfully");
}
else if(http.ResponseHeaders.TryGetFirst("Content-Type") == "application/json")
{
var json = Json.Decode(http.ReadAsString());
Console.WriteLine($"Failed to upload package, {json.reason.TrimEnd('.')}.");
}
else {
Console.WriteLine($"Failed to upload package.");
}
strm.Close();
}
else if(commandName == "login")
{
//crosslang login local https://cpkg.tesseslanguage.com/
//crosslang login [NAME] [HOST] [TOKEN]
} }
else if(commandName == "configdir") else if(commandName == "configdir")
{ {
Console.WriteLine(Env.CrossLangConfig); Console.WriteLine(Env.CrossLangConfig);
} }
} }
else else
{ {

View File

@@ -1,41 +1,29 @@
/^ class Exception
Create a new exception
^/
func New.Exception(message,$type,$inner)
{ {
if(TypeIsString(type)) public Message;
public InnerException;
public Exception(message,$inner)
{ {
return { this.Message = message;
Message = message, this.InnerException = inner;
InnerException = inner,
Type = type,
ToString = Std.Internal.Exception.ToString
};
} }
else
public ToString()
{ {
return { var messagePart = $"{Class.Name(this)}: {Message}";
Message = message, if(InnerException != undefined && InnerException != null)
InnerException = inner, {
Type = "Exception", var innerEx = InnerException.ToString().Replace("\n","\n\t");
ToString = Std.Internal.Exception.ToString return $"{messagePart}\nInner exception:\n{innerEx}";
}; }
return messagePart;
} }
} }
/^Out of range exception^/
func New.OutOfRangeException(varName, $inner)
{
return new Exception($"{varName} is out of range.","OutOfRangeException",inner);
}
/^Exception ToString^/
func Std.Internal.Exception.ToString(this)
{
var messagePart = $"{this.Type}: {this.Message}";
if(this.InnerException != undefined && this.InnerException != null)
{
var innerEx = this.InnerException.ToString().Replace("\n","\n\t");
return $"{messagePart}\nInner exception:\n{innerEx}";
}
return messagePart;
}
class OutOfRangeException : Exception
{
public OutOfRangeException(varName,$inner)
{
Exception($"{varName} is out of range.",inner);
}
}

View File

@@ -27,18 +27,21 @@ func main(args)
cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","Tesses.CrossLang.PackageServer"]); cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","Tesses.CrossLang.PackageServer"]);
//cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","Tesses.CrossLang.WebSite"]); //cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","Tesses.CrossLang.WebSite"]);
cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","Tesses.CrossLang.Std"]); cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","Tesses.CrossLang.Std"]);
cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","Templates/console"]); cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","Templates/console"]);
cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","Templates/emptyweb"]); cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","Templates/emptyweb"]);
cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","Templates/web"]); cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","Templates/web"]);
cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","Templates/template"]); cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","Templates/template"]);
cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","Templates/lib"]); cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","Templates/lib"]);
cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","Templates/compiletool"]); cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","Templates/compiletool"]);
cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","Templates/tool"]); cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","Templates/tool"]);
/*cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","Tesses.CrossLang.PackageServer"]); cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","Templates/gui"]);
/*
cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","Tesses.CrossLang.PackageServer"]); cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","Tesses.CrossLang.PackageServer"]);
cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","Tesses.CrossLang.PackageServer"]); cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","Tesses.CrossLang.PackageServer"]);
cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","Tesses.CrossLang.PackageServer"]); cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","Tesses.CrossLang.PackageServer"]);
cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","Tesses.CrossLang.PackageServer"]);*/ cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","Tesses.CrossLang.PackageServer"]);
cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","Tesses.CrossLang.PackageServer"]);
*/
cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","crosslang_shell_archive_maker"]); cmd("crossvm",["./Tesses.CrossLang.Shell/bin/Tesses.CrossLang.Shell-1.0.0.0-prod.crvm","build","crosslang_shell_archive_maker"]);
if(args.Length > 1) if(args.Length > 1)

View File

@@ -54,6 +54,8 @@ func create_archive()
copyFile("Templates/web/bin/Tesses.CrossLang.Template.Website-1.0.0.0-prod.crvm", templates / "web.crvm"); copyFile("Templates/web/bin/Tesses.CrossLang.Template.Website-1.0.0.0-prod.crvm", templates / "web.crvm");
copyFile("Templates/emptyweb/bin/Tesses.CrossLang.Template.EmptyWebsite-1.0.0.0-prod.crvm", templates / "emptyweb.crvm"); copyFile("Templates/emptyweb/bin/Tesses.CrossLang.Template.EmptyWebsite-1.0.0.0-prod.crvm", templates / "emptyweb.crvm");
copyFile("Templates/tool/bin/Tesses.CrossLang.Template.Tool-1.0.0.0-prod.crvm", templates / "tool.crvm"); copyFile("Templates/tool/bin/Tesses.CrossLang.Template.Tool-1.0.0.0-prod.crvm", templates / "tool.crvm");
copyFile("Templates/gui/bin/Tesses.CrossLang.Template.GUI-1.0.0.0-prod.crvm", templates / "gui.crvm");
var packageCache = r / "PackageCache"; var packageCache = r / "PackageCache";
tmpFS.CreateDirectory(packageCache); tmpFS.CreateDirectory(packageCache);

View File

@@ -38,7 +38,7 @@ namespace Tesses.CrossLang
public string license {get;set;}=""; //optional, but recommended to tell people what the license is public string license {get;set;}=""; //optional, but recommended to tell people what the license is
public string readme {get;set;}=""; //optional but tells people about the package public string description {get;set;}=""; //optional but tells people about the package
} }
public static void Main(string[] args) public static void Main(string[] args)

View File

@@ -3,4 +3,4 @@ lib: a library
app: a gui app (used for eventual gui system) app: a gui app (used for eventual gui system)
template: used for project templates template: used for project templates
compile_tool: run before source is compiled for project if it is in the dependency tree for the project (and is not linked to said projects) compile_tool: run before source is compiled for project if it is in the dependency tree for the project (and is not linked to said projects)
tool: a tool invokable via crosslang tool: a tool invokable via crosslang (gets Tesses.CrossLang.Args for free)