| 25 |
split /[\x0D\x0A]+/, $cgi->get_parameter ('tags') // '']; |
split /[\x0D\x0A]+/, $cgi->get_parameter ('tags') // '']; |
| 26 |
|
|
| 27 |
my $hash = get_hash ($en); |
my $hash = get_hash ($en); |
| 28 |
|
my $entry = {en => $en, ja => $ja, tags => $tags}; |
| 29 |
|
|
| 30 |
lock_entry ($hash); |
lock_entry ($hash); |
| 31 |
set_entry ($hash, $is_pattern => {en => $en, ja => $ja, tags => $tags}); |
set_entry ($hash, $is_pattern => $entry); |
| 32 |
commit_entries ("$path: $hash updated by $ENV{AUTH_USER}"); |
commit_entries ("$path: $hash updated by $ENV{AUTH_USER}"); |
| 33 |
|
|
| 34 |
print "Status: 204 Saved\n\n"; |
print "Status: 200 Saved\n"; |
| 35 |
|
|
| 36 |
|
my $updates = {$hash => $entry}; |
| 37 |
|
|
| 38 |
|
binmode STDOUT, ':encoding(utf-8)'; |
| 39 |
|
print "Content-Type: application/json\n\n"; |
| 40 |
|
|
| 41 |
|
require JSON; |
| 42 |
|
print scalar JSON::objToJson ($updates); |
| 43 |
exit; |
exit; |
| 44 |
} else { |
} else { |
| 45 |
print q[Status: 405 Method Not Allowed |
print q[Status: 405 Method Not Allowed |
| 51 |
} |
} |
| 52 |
} elsif ($path =~ m#^/([0-9a-f]+)\.json$#) { |
} elsif ($path =~ m#^/([0-9a-f]+)\.json$#) { |
| 53 |
my $hash = $1; |
my $hash = $1; |
| 54 |
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; |
|
| 55 |
|
|
| 56 |
binmode STDOUT, ':encoding(utf-8)'; |
binmode STDOUT, ':encoding(utf-8)'; |
| 57 |
print "Content-Type: application/json\n\n"; |
print "Content-Type: application/json\n\n"; |
| 59 |
require JSON; |
require JSON; |
| 60 |
print scalar JSON::objToJson ($entry); |
print scalar JSON::objToJson ($entry); |
| 61 |
exit; |
exit; |
| 62 |
|
} elsif ($path eq '/updates.json') { |
| 63 |
|
my $updates = {}; |
| 64 |
|
for (get_modified_hashes ()) { |
| 65 |
|
$updates->{$_} = get_entry_or_fallback_entry ($_); |
| 66 |
|
} |
| 67 |
|
|
| 68 |
|
binmode STDOUT, ':encoding(utf-8)'; |
| 69 |
|
print "Content-Type: application/json\n\n"; |
| 70 |
|
|
| 71 |
|
require JSON; |
| 72 |
|
print scalar JSON::objToJson ($updates); |
| 73 |
|
exit; |
| 74 |
} |
} |
| 75 |
|
|
| 76 |
print q[Content-Type: text/plain ; charset=us-ascii |
print q[Content-Type: text/plain ; charset=us-ascii |