| 18 |
return Encode::decode ('utf-8', $_[1]); |
return Encode::decode ('utf-8', $_[1]); |
| 19 |
}; |
}; |
| 20 |
|
|
| 21 |
my $en = $cgi->get_parameter ('en'); |
my $en = normalize_width ($cgi->get_parameter ('en')); |
| 22 |
my $ja = $cgi->get_parameter ('ja'); |
my $ja = normalize_width ($cgi->get_parameter ('ja')); |
| 23 |
my $is_pattern = $cgi->get_parameter ('pattern'); |
my $is_pattern = $cgi->get_parameter ('pattern'); |
| 24 |
my $tags = [map {normalize ($_)} |
my $tags = [map {normalize ($_)} |
| 25 |
split /[\x0D\x0A]+/, $cgi->get_parameter ('tags') // '']; |
split /[\x0D\x0A]+/, |
| 26 |
|
normalize_width ($cgi->get_parameter ('tags') // '')]; |
| 27 |
|
|
| 28 |
my $hash = get_hash ($en); |
my $hash = get_hash ($en); |
| 29 |
|
my $entry = {en => $en, ja => $ja, tags => $tags, |
| 30 |
|
isPattern => $is_pattern}; |
| 31 |
|
|
| 32 |
lock_entry ($hash); |
lock_entry ($hash); |
| 33 |
set_entry ($hash, $is_pattern => {en => $en, ja => $ja, tags => $tags}); |
set_entry ($hash, $is_pattern => $entry); |
| 34 |
commit_entries ("$path: $hash updated by $ENV{AUTH_USER}"); |
commit_entries ("$path: $hash updated by $ENV{REMOTE_USER}"); |
| 35 |
|
|
| 36 |
|
print "Status: 200 Saved\n"; |
| 37 |
|
|
| 38 |
|
my $updates = {$hash => $entry}; |
| 39 |
|
|
| 40 |
print "Status: 204 Saved\n\n"; |
binmode STDOUT, ':encoding(utf-8)'; |
| 41 |
|
print "Content-Type: application/json\n\n"; |
| 42 |
|
|
| 43 |
|
require JSON; |
| 44 |
|
print scalar JSON::objToJson ($updates); |
| 45 |
exit; |
exit; |
| 46 |
} else { |
} else { |
| 47 |
print q[Status: 405 Method Not Allowed |
print q[Status: 405 Method Not Allowed |
| 53 |
} |
} |
| 54 |
} elsif ($path =~ m#^/([0-9a-f]+)\.json$#) { |
} elsif ($path =~ m#^/([0-9a-f]+)\.json$#) { |
| 55 |
my $hash = $1; |
my $hash = $1; |
| 56 |
my ($is_pattern, $entry) = get_entry ($hash); |
my $entry = get_entry_or_fallback_entry ($hash); |
|
unless (defined $entry->{en}) { |
|
|
$entry = get_fallback_entry ($hash); |
|
|
} |
|
|
$entry->{tags} ||= [] if defined $entry->{en}; |
|
|
$entry->{isPattern} = 1 if $is_pattern; |
|
| 57 |
|
|
| 58 |
binmode STDOUT, ':encoding(utf-8)'; |
binmode STDOUT, ':encoding(utf-8)'; |
| 59 |
print "Content-Type: application/json\n\n"; |
print "Content-Type: application/json\n\n"; |
| 61 |
require JSON; |
require JSON; |
| 62 |
print scalar JSON::objToJson ($entry); |
print scalar JSON::objToJson ($entry); |
| 63 |
exit; |
exit; |
| 64 |
|
} elsif ($path eq '/updates.json') { |
| 65 |
|
my $updates = {}; |
| 66 |
|
for (get_modified_hashes ()) { |
| 67 |
|
$updates->{$_} = get_entry_or_fallback_entry ($_); |
| 68 |
|
} |
| 69 |
|
|
| 70 |
|
binmode STDOUT, ':encoding(utf-8)'; |
| 71 |
|
print "Content-Type: application/json\n\n"; |
| 72 |
|
|
| 73 |
|
require JSON; |
| 74 |
|
print scalar JSON::objToJson ($updates); |
| 75 |
|
exit; |
| 76 |
} |
} |
| 77 |
|
|
| 78 |
print q[Content-Type: text/plain ; charset=us-ascii |
print q[Content-Type: text/plain ; charset=us-ascii |
| 79 |
Status: 404 Not Found |
Status: 404 Not Found |
| 80 |
|
|
| 81 |
404]; |
404]; |
| 82 |
|
|
| 83 |
|
## Author: Wakaba <w@suika.fam.cx>. |
| 84 |
|
## License: Copyright 2008 Wakaba. You are granted a license to use, |
| 85 |
|
## reproduce and create derivative works of this script. |
| 86 |
|
## $Date$ |