sora 24.02.25

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 595fdec94ad7aa62fa2490265ffd6633b039773570518115afd13446cf75f5aa
4
+ data.tar.gz: bab57e34ef9eb436ea590c8e5a3988cdd780e4ae657a254c5ecaadff82ef7239
5
+ SHA512:
6
+ metadata.gz: 221d63074168d433bbff41cb5507e381fa683b9e6ba8c5a46234b3c6e0764d38e0097582eda7981eb156098783058ef968a8612509813767bf8535d3fd2ff4af
7
+ data.tar.gz: 6c70324213cbf7a197939305b3c8892d3a4a7656ad6b689773fdc836354545f460ca06a257e899e034c374b22bf338c317426c0f2414e0115d2bb419df6c728c
data/.rubocop.yml ADDED
@@ -0,0 +1,19 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
14
+
15
+ Layout/EndOfLine:
16
+ Enabled: False
17
+
18
+ Metrics/MethodLength:
19
+ Enabled: False
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-02-24
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at TODO: Write your email address. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ # Sora
2
+ sora is an http server in Ruby that can send and receive strings and files.
3
+
4
+ sora (Server Of Ruby for Access) can send and receive files, and transmit text strings to communicate information.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
data/cgi-bin/main.rb ADDED
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "cgi"
4
+ require "json"
5
+ require "securerandom"
6
+
7
+ cgi = CGI.new
8
+ print cgi.header("application/json")
9
+ params = cgi.params
10
+ @json_file_path = "../data/data.json"
11
+
12
+ def read_json(filename)
13
+ unless File.exist? filename
14
+ File.open(filename, "w") do |f|
15
+ f.write "[]"
16
+ end
17
+ end
18
+ json = []
19
+ File.open(filename, "r") do |f|
20
+ json = JSON.parse(f.read)
21
+ end
22
+ json
23
+ end
24
+
25
+ def get_json(params)
26
+ return unless params.key?("data")
27
+
28
+ data = params["data"][0]
29
+ json = read_json(@json_file_path)
30
+
31
+ if data != "" && !data.nil?
32
+ json.append({
33
+ content: data,
34
+ uuid: SecureRandom.uuid
35
+ })
36
+ File.open(@json_file_path, "w") do |f|
37
+ f.write JSON.pretty_generate(json)
38
+ end
39
+ end
40
+ print(JSON.pretty_generate(json))
41
+ end
42
+
43
+ def delete(params)
44
+ return unless params.key?("delete")
45
+
46
+ json = read_json(@json_file_path)
47
+
48
+ json = json.filter { |e| e["uuid"] != params["delete"][0] }
49
+ File.open(@json_file_path, "w") do |f|
50
+ f.write JSON.pretty_generate(json)
51
+ end
52
+
53
+ response = {
54
+ uuid: params["delete"][0],
55
+ status: "OK"
56
+ }
57
+ print JSON.pretty_generate(response)
58
+ end
59
+
60
+ get_json(params)
61
+ delete(params)
data/data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ data.json
data/exe/sora ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "sora"
5
+ require "optparse"
6
+
7
+ opt = OptionParser.new
8
+
9
+ params = { port: 8080, document_root: File.expand_path("../../www", __FILE__) }
10
+
11
+ opt.on("-p [PORT]", "--port [PORT]") { |v| params[:port] = v.to_i }
12
+
13
+ opt.parse!(ARGV)
14
+
15
+ Sora.server(**params)
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sora
4
+ VERSION = "24.02.25"
5
+ end
data/lib/sora.rb ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "sora/version"
4
+
5
+ # sora module
6
+ module Sora
7
+ class Error < StandardError; end
8
+ # Your code goes here...
9
+
10
+ require "webrick"
11
+
12
+ def server(port: 8080, document_root: "./")
13
+ srv = WEBrick::HTTPServer.new(
14
+ {
15
+ DocumentRoot: document_root,
16
+ BindAddress: "0.0.0.0",
17
+ Port: port,
18
+ CGIInterpreter: RbConfig.ruby
19
+ }
20
+ )
21
+ srv.mount("/cgi-bin", WEBrick::HTTPServlet::CGIHandler, "#{document_root}/../cgi-bin/main.rb")
22
+ srv.mount("/", WEBrick::HTTPServlet::FileHandler, "#{document_root}/index.html")
23
+ srv.mount("/style", WEBrick::HTTPServlet::FileHandler, "#{document_root}/style.css")
24
+ srv.mount("/js", WEBrick::HTTPServlet::FileHandler, "#{document_root}/main.js")
25
+ trap("INT") { srv.shutdown }
26
+ srv.start
27
+ end
28
+
29
+ module_function :server
30
+ end
data/sig/sora.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Sora
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
data/www/index.html ADDED
@@ -0,0 +1,28 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+
4
+ <head>
5
+ <meta charset="utf-8">
6
+ <title>sora</title>
7
+ <link rel="stylesheet" href="/style">
8
+ <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
9
+ </head>
10
+
11
+ <body>
12
+ <main id="main">
13
+ <h1>sora</h1>
14
+ <div class="Grid Text-SendButton">
15
+ <input id="content" placeholder="Text..." class="TextBox" />
16
+ <input type="button" id="send-button" value="Send" class="Accent Button SendButton" />
17
+ </div>
18
+ <div id="data-list"></div>
19
+ </main>
20
+ <div id="contextmenu">
21
+ <ul>
22
+ <li id="right-click-delete">Delete</li>
23
+ </ul>
24
+ </div>
25
+ <script src="/js"></script>
26
+ </body>
27
+
28
+ </html>
data/www/main.js ADDED
@@ -0,0 +1,84 @@
1
+ function EncodeHTMLForm(data) {
2
+ var params = [];
3
+ for (var name in data) {
4
+ var value = data[name];
5
+ var param = encodeURIComponent(name) + '=' + encodeURIComponent(value);
6
+
7
+ params.push(param);
8
+ }
9
+ return params.join('&').replace(/%20/g, '+');
10
+ }
11
+
12
+ const content = document.getElementById("content");
13
+ const sendButton = document.getElementById("send-button");
14
+ const rightClickDelete = document.getElementById("right-click-delete");
15
+ let rightClickTargetId = "";
16
+ let data = [];
17
+
18
+ const refresh = () => {
19
+ if(data == null) return;
20
+ const dataList = document.getElementById("data-list");
21
+ dataList.innerHTML = "";
22
+ for(const text of data){
23
+ const div = document.createElement("div");
24
+ div.innerText = text['content'];
25
+ div.className = "message";
26
+ div.id = text['uuid'];
27
+ dataList.prepend(div);
28
+
29
+ const contextmenu = document.getElementById('contextmenu');
30
+ const main = div;
31
+ main.addEventListener('contextmenu', (e) => {
32
+ e.preventDefault();
33
+ contextmenu.style.left = e.pageX + 'px';
34
+ contextmenu.style.top = e.pageY + 'px';
35
+ contextmenu.style.display = 'block';
36
+ rightClickTargetId = e.target.id
37
+ });
38
+ main.addEventListener('click', () => {
39
+ contextmenu.style.display = 'none';
40
+ });
41
+ }
42
+ }
43
+
44
+ const send = (write) => {
45
+ const xhr = new XMLHttpRequest();
46
+ xhr.open("POST", "/cgi-bin");
47
+ write ? xhr.send(EncodeHTMLForm({ "data": content.value })) : xhr.send(EncodeHTMLForm({ "data": "" }));
48
+ xhr.onreadystatechange = () => {
49
+ let texts = JSON.parse(xhr.responseText || "null");
50
+ if(texts == null) return;
51
+ data = texts;
52
+ refresh();
53
+ }
54
+ }
55
+
56
+ const i18n = () => {
57
+ const lang = window.navigator.language;
58
+ if(lang == 'ja'){
59
+ content.placeholder = "テキストを入力...";
60
+ sendButton.value = "送信";
61
+ rightClickDelete.innerText = "削除"
62
+ }
63
+ }
64
+
65
+ rightClickDelete.addEventListener('click', () => {
66
+ const targetDOM = document.getElementById(rightClickTargetId);
67
+ targetDOM.remove();
68
+
69
+ const xhr = new XMLHttpRequest();
70
+ xhr.open("POST", "/cgi-bin");
71
+ xhr.send(EncodeHTMLForm({"delete": rightClickTargetId}));
72
+ xhr.onreadystatechange = () => {
73
+ let texts = JSON.parse(xhr.responseText || "null");
74
+ if(texts == null) return;
75
+ if(texts["status"] == "OK"){
76
+ send(false);
77
+ }
78
+ };
79
+ contextmenu.style.display = 'none';
80
+ });
81
+
82
+ i18n();
83
+ send(false);
84
+ sendButton.addEventListener("click", () => { send(true) });
data/www/style.css ADDED
@@ -0,0 +1,126 @@
1
+ body{
2
+ background-color: #F3F3F3;
3
+ font-family: Segoe UI, Meiryo UI;
4
+ }
5
+
6
+ main{
7
+ max-width: 980px;
8
+ margin: 0 auto;
9
+ }
10
+
11
+ .Grid{
12
+ display: grid;
13
+ }
14
+
15
+ .Text-SendButton{
16
+ grid-template-columns: 1fr auto;
17
+ margin-bottom: 8px;
18
+ }
19
+
20
+ .Text-SendButton .TextBox{
21
+ margin-right: 8px;
22
+ }
23
+
24
+ .message{
25
+ margin-bottom: 8px;
26
+ padding: 16px;
27
+ border: solid 1px #E5E5E5;
28
+ background-color: #F4F4F4;
29
+ border-radius: 4px;
30
+ font-size: 14px;
31
+ }
32
+
33
+ /* 右クリックメニュー */
34
+ #contextmenu {
35
+ display: none;
36
+ position: fixed;
37
+ left: 0;
38
+ top: 0;
39
+ border-radius: 8px;
40
+ background-color: #F9F9F9;
41
+ border: solid 1px #E3E3E3;
42
+ padding: 4px;
43
+ width: 192px;
44
+ }
45
+
46
+ #contextmenu ul{
47
+ padding-left: 0;
48
+ margin: 0;
49
+ }
50
+
51
+ #contextmenu li {
52
+ cursor: pointer;
53
+ margin: 0;
54
+ padding: 4.75px 0 4.75px 16px;
55
+ border-radius: 4px;
56
+ list-style: none;
57
+ font-size: 14px;
58
+ user-select: none;
59
+ }
60
+
61
+ #contextmenu li:hover {
62
+ background-color: #F0F0F0;
63
+ }
64
+
65
+ /* 共通コンポーネント */
66
+ .TextBox{
67
+ height: 27px;
68
+ border: solid 1px #E5E5E5;
69
+ border-bottom-color: #868686;
70
+ border-radius: 4px;
71
+ padding-left: 11px;
72
+ padding-bottom: 2px;
73
+ background-color: #FBFBFB;
74
+ }
75
+
76
+ .TextBox:hover{
77
+ background-color: #F6F6F6;
78
+ }
79
+
80
+ .TextBox:focus{
81
+ background-color: white;
82
+ height: 27px;
83
+ border-bottom-color: #0067C0;
84
+ border-bottom-width: 2px;
85
+ outline: none;
86
+ padding-bottom: 1px;
87
+ }
88
+
89
+ .Button{
90
+ height: 32px;
91
+ border: solid 1px #E5E5E5;
92
+ border-bottom-color: #CCCCCC;
93
+ background-color: white;
94
+ border-radius: 4px;
95
+ padding: 1px 12px;
96
+ }
97
+
98
+ .Button:hover{
99
+ background-color: #F6F6F6;
100
+ }
101
+
102
+ .Button:active{
103
+ background-color: #F5F5F5;
104
+ color: #5D5D5D;
105
+ border-color: #E5E5E5;
106
+ }
107
+
108
+ .Button.Accent{
109
+ background-color: #0067C0;
110
+ border: solid 1px #1473C5;
111
+ border-bottom-color: #003E73;
112
+ color: white;
113
+ }
114
+
115
+ .Button.Accent:hover{
116
+ background-color: #1975C5;
117
+ border: solid 1px #2B80CA;
118
+ border-bottom-color: #0F4676;
119
+ }
120
+
121
+ .Button.Accent:active{
122
+ background-color: #3183CA;
123
+ border: solid 1px #3183CA;
124
+ border-bottom-color: #3183CA;
125
+ color: #C2DAEF;
126
+ }
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sora
3
+ version: !ruby/object:Gem::Version
4
+ version: 24.02.25
5
+ platform: ruby
6
+ authors:
7
+ - MURATA Mitsuharu
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-02-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: sora (Server Of Ruby for Access) can send and receive files, and transmit
14
+ text strings to communicate information.
15
+ email:
16
+ - hikari.photon+dev@gmail.com
17
+ executables:
18
+ - sora
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - ".rubocop.yml"
23
+ - CHANGELOG.md
24
+ - CODE_OF_CONDUCT.md
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - cgi-bin/main.rb
29
+ - data/.gitignore
30
+ - exe/sora
31
+ - lib/sora.rb
32
+ - lib/sora/version.rb
33
+ - sig/sora.rbs
34
+ - www/index.html
35
+ - www/main.js
36
+ - www/style.css
37
+ homepage: https://github.com/Himeyama/sora
38
+ licenses:
39
+ - MIT
40
+ metadata:
41
+ homepage_uri: https://github.com/Himeyama/sora
42
+ source_code_uri: https://github.com/Himeyama/sora
43
+ changelog_uri: https://github.com/Himeyama/sora/blob/master/CHANGELOG.md
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 2.6.0
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubygems_version: 3.4.19
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: sora is an http server in Ruby that can send and receive strings and files.
63
+ test_files: []