-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3751fef
commit 4952195
Showing
9 changed files
with
183 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = tab | ||
tab_width = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.yml] | ||
indent_style = space |
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,6 @@ | ||
.DS_Store | ||
/node_modules | ||
*-lock.* | ||
*.lock | ||
*.log | ||
.wrangler |
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,19 @@ | ||
{ | ||
"semi": true, | ||
"printWidth": 100, | ||
"singleQuote": true, | ||
"bracketSpacing": true, | ||
"insertPragma": false, | ||
"requirePragma": false, | ||
"jsxSingleQuote": false, | ||
"bracketSameLine": false, | ||
"embeddedLanguageFormatting": "auto", | ||
"htmlWhitespaceSensitivity": "css", | ||
"vueIndentScriptAndStyle": true, | ||
"quoteProps": "consistent", | ||
"proseWrap": "preserve", | ||
"trailingComma": "es5", | ||
"arrowParens": "avoid", | ||
"useTabs": true, | ||
"tabWidth": 2 | ||
} |
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,31 @@ | ||
## Template: worker-router | ||
|
||
[![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/templates/tree/main/worker-router) | ||
|
||
This template demonstrates using the [`itty-router`](https://github.com/kwhitley/itty-router) package to add routing to your Cloudflare Workers. | ||
|
||
[`index.js`](https://github.com/cloudflare/worker-template-router/blob/master/index.js) is the content of the Workers script. | ||
|
||
## Setup | ||
|
||
To create a `my-project` directory using this template, run: | ||
|
||
```sh | ||
$ npx wrangler generate my-project worker | ||
# or | ||
$ yarn wrangler generate my-project worker | ||
# or | ||
$ pnpm wrangler generate my-project worker | ||
``` | ||
|
||
Before publishing your code you need to edit `wrangler.toml` file and add your Cloudflare `account_id` - more information about configuring and publishing your code can be found [in the documentation](https://developers.cloudflare.com/workers/learning/getting-started). | ||
|
||
Once you are ready, you can publish your code by running the following command: | ||
|
||
```sh | ||
$ npm run deploy | ||
# or | ||
$ yarn run deploy | ||
# or | ||
$ pnpm run deploy | ||
``` |
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 @@ | ||
|
||
/* | ||
* @param {string} stufe - The grade of the student. | ||
* @param {string} klasse - The class of the student. | ||
* @param {boolean} isStudent - Whether the user is a student or Teacher/Parent. | ||
* | ||
* @returns {Object} - The extracted data from the input. | ||
* */ | ||
export function defaultSubstitutionsFilterExtractor(stufe, klasse, isStudent) { | ||
klasse = klasse.toLowerCase(); | ||
|
||
//Oberstufenklassen haben oft sehr seltsame Bezeichnungen. Diese sollen primär schulspezifisch gehandhabt werden. | ||
if (klasse.includes("q") || klasse.includes("e")) { | ||
//get first digit from string | ||
let klasseMatch = klasse.match(/\d+/); | ||
return { | ||
"stufe": klasse.includes("q") ? "Q" : "E", | ||
"klasse": klasseMatch ? klasseMatch[0] : "", | ||
"lehrer": "", | ||
} | ||
} | ||
|
||
//Klassenbezeichnungen wie 5a, 5b, 5c, 5d, 10a, 10b, 13c etc. | ||
//lösung mit regex | ||
let klasseMatch = klasse.match(/(\d+)([a-zA-Z]+)/); | ||
if (klasseMatch) { | ||
return { | ||
"stufe": parseInt(klasseMatch[1]), | ||
"klasse": klasseMatch[2], | ||
"lehrer": "", | ||
} | ||
} | ||
|
||
|
||
return {klasse: "", stufe: "", lehrer: ""}; | ||
} |
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,32 @@ | ||
import { Router } from 'itty-router'; | ||
import SCHOOL_CONFIGS from "./school_config"; | ||
|
||
const router = Router(); | ||
|
||
|
||
|
||
router.get('/substitutions/:schoolID', ({ params, query }) => { | ||
const { schoolID } = params; | ||
const { stufe, klasse, isStudent } = query; | ||
|
||
let result; | ||
|
||
if (!SCHOOL_CONFIGS[schoolID]) { | ||
result = SCHOOL_CONFIGS["default"](stufe, klasse, isStudent); | ||
} else { | ||
result = SCHOOL_CONFIGS[schoolID](stufe, klasse, isStudent); | ||
} | ||
|
||
return new Response(JSON.stringify(result), { | ||
headers: { | ||
'Content-Type': "application/json", | ||
}, | ||
}); | ||
}); | ||
|
||
|
||
router.all('*', () => new Response("",{status: 302, headers: {"location": "https://github.com/alessioc42/lanis-mobile-autoconfig"} })); | ||
|
||
export default { | ||
fetch: router.handle, | ||
}; |
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 @@ | ||
{ | ||
"name": "template-worker-router", | ||
"version": "0.0.0", | ||
"private": true, | ||
"scripts": { | ||
"deploy": "wrangler deploy index.js", | ||
"dev": "wrangler dev index.js", | ||
"test": "vitest" | ||
}, | ||
"dependencies": { | ||
"itty-router": "^2.6.1" | ||
}, | ||
"devDependencies": { | ||
"wrangler": "^3.0.0" | ||
} | ||
} |
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,27 @@ | ||
import {defaultSubstitutionsFilterExtractor} from "./defaultparser"; | ||
|
||
|
||
let SCHOOL_CONFIGS = { | ||
"default": (stufe, klasse, isStudent) => { | ||
return defaultSubstitutionsFilterExtractor(stufe, klasse, isStudent) | ||
}, | ||
//Configs for Max-Planck-Schule Rüsselsheim | ||
"5182": (stufe, klasse, isStudent) => { | ||
let result = defaultSubstitutionsFilterExtractor(stufe, klasse, isStudent); | ||
|
||
if (result.stufe === "Q" || result.stufe === "E") { | ||
switch (result.klasse) { | ||
case "1" || "2": | ||
result.klasse = "1/2"; | ||
break; | ||
case "3" || "4": | ||
result.klasse = "3/4"; | ||
break; | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
} | ||
|
||
export default SCHOOL_CONFIGS; |
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,3 @@ | ||
name = "lanis-mobile-autoconfig" | ||
main = "index.js" | ||
compatibility_date = "2022-05-03" |